-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
Databind 1.x had colored tracebacks for location errors:
python-databind/databind.core/src/databind/core/mapper/location.py
Lines 71 to 113 in 33eb809
| 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
