You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When rich printing a dataclass:
If the last field has its repr disabled: repr=False
Then, the pretty_repr will contain a trailing comma and whitespace.
To Reproduce
fromdataclassesimportdataclass, field, fieldsimportrichfromrichimportpretty, _loop@dataclassclassExpectedCase:
first: bool=True_none: bool=field(init=False, repr=False)
last: bool=True@dataclassclassTrailingComma:
first: bool=Truelast: bool=True_none: bool=field(init=False, repr=False)
if__name__=='__main__':
# demonstrationrich.print(TrailingComma())
# highlighttrailing_repr=rich.pretty.pretty_repr(TrailingComma())
print(' '* (len(trailing_repr) -4), '^^ \n')
# show the issues sourceforexamplein [ExpectedCase(), TrailingComma()]:
print('rich.print(): ', end='')
rich.print(example)
rich.print(f'rich f-string: {example}')
print('builtin print:', example, '\n')
print(f'dataclass Fields: ')
example_fields=fields(example)
forfieldinexample_fields:
rich.print(f' {field.name!r:7} -> repr={field.repr}')
print()
print('rich._loop.loop_last() yields: ')
forlast, fieldinrich._loop.loop_last(example_fields):
rich.print(f' {last=!r:5}, field={field.name!r}')
print()
# possible to have no node marked as the last:print('rich.pretty.traverse() returns Nodes: ')
fornodeinrich.pretty.traverse(example).children:
rich.print(f' {node.key_repr=}, {node.last=}')
print('\n')
grep: The term 'grep' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
The text was updated successfully, but these errors were encountered:
Dataclass pretty repr can contain a trailing separator and whitespace
Fixed pretty_repr() for dataclass fields with repr=False.
Fixed corresponding test.
10.13.0
Added
Added json.dumps parameters to print_json Textualize/rich#1638
Fixed
Fixed an edge case bug when console module try to detect if they are in a tty at the end of a pytest run
Fixed a bug where logging handler raises an exception when running with pythonw (related to https://bugs.python.org/issue13807)
Fixed issue with TERM env vars that have more than one hyphen Textualize/rich#1640
Fixed missing new line after progress bar when terminal is not interactive Textualize/rich#1606
Fixed exception in IPython when disabling pprint with %pprint Textualize/rich#1646
Fixed issue where values longer than the console width produced invalid JSON Textualize/rich#1653
Fixes trailing comma when pretty printing dataclass with last field repr=False Textualize/rich#1599
Changed
Markdown codeblocks now word-wrap
When rich printing a dataclass:
If the last field has its
repr
disabled:repr=False
Then, the pretty_repr will contain a trailing comma and whitespace.
To Reproduce
Outputs:
Platform
Windows, Windows Terminal/Powershell 7
Diagnose
I may ask you to cut and paste the output of the following commands. It may save some time if you do it now.
python -m rich.diagnose
python -m rich._windows
pip freeze | grep rich
The text was updated successfully, but these errors were encountered: