Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back colored traceback for ConversionError #45

Open
NiklasRosenstein opened this issue May 28, 2023 · 0 comments
Open

Bring back colored traceback for ConversionError #45

NiklasRosenstein opened this issue May 28, 2023 · 0 comments
Assignees

Comments

@NiklasRosenstein
Copy link
Owner

NiklasRosenstein commented May 28, 2023

Databind 1.x had colored tracebacks for location errors:

image

def format(
self,
indent: str = ' ',
list_item: str = '-',
filenames: bool = True,
sparse_filenames: bool = True,
collapse: bool = False,
colors: t.Optional[bool] = None,
) -> str:
"""
Converts the location to a string representation of the form
- $ (type) [filename:line:col]
- key (type) [filename:line:col]
...
"""
if colors is None and sys.stdout.isatty():
colors = True
c = t.cast(t.Callable, colored if colors else _no_colored)
parts: t.List[str] = []
prev_filename: t.Optional[str] = None
for loc in _get_location_chain(self):
source_changed = filenames and bool(not prev_filename or loc.filename and loc.filename != prev_filename)
if collapse and parts and not source_changed and not loc.key:
continue
name = '$' if loc.key is None else f'.{loc.key}'
parts.append(f'{indent}{list_item} {c(name, "cyan")} {c("(" + str(loc.type) + ")", "green")}')
if not sparse_filenames or source_changed:
parts.append(' ')
parts.append(c(_get_filename_and_pos_string(loc.filename, loc.pos), 'magenta'))
parts.append('\n')
if loc.filename:
prev_filename = loc.filename
parts.pop() # Remove the last newline
return ''.join(parts)

We should bring that feature back in Databind 4.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant