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

Fix using tuples as positional arguments in rich repr #2379

Merged

Conversation

saulshanabrook
Copy link
Contributor

@saulshanabrook saulshanabrook commented Jul 5, 2022

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

Currently, it isn't possible to use tuples as positional arguments from __rich_repr__, because they are special cased to support adding a key and a default value.

This adds support for them, by allowing None as a key.

Currently, it isn't possible to use tuples as positional arguments from `__rich_repr__`, because they are special cased to support adding a key and a default value.

This adds support for them, by allowing `None` as a key.
@saulshanabrook saulshanabrook changed the title Support tuples as positional arguments in rich repr Fix using tuples as positional arguments in rich repr Jul 5, 2022
@saulshanabrook saulshanabrook marked this pull request as ready for review July 5, 2022 13:47
@willmcgugan
Copy link
Collaborator

This already works:

class Foo:
    def __rich_repr__(self):
        yield None, (1,)

f=Foo()
from rich import print
print(f)

If its not documented, that should certainly be rectified.

@codecov-commenter
Copy link

codecov-commenter commented Jul 11, 2022

Codecov Report

Merging #2379 (21b51aa) into master (19e518f) will decrease coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2379      +/-   ##
==========================================
- Coverage   98.71%   98.67%   -0.05%     
==========================================
  Files          73       72       -1     
  Lines        7771     7746      -25     
==========================================
- Hits         7671     7643      -28     
- Misses        100      103       +3     
Flag Coverage Δ
unittests 98.67% <100.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
rich/default_styles.py 100.00% <ø> (ø)
rich/_inspect.py 100.00% <100.00%> (ø)
rich/cells.py 96.05% <100.00%> (-3.95%) ⬇️
rich/console.py 98.30% <100.00%> (+0.01%) ⬆️
rich/pretty.py 99.21% <100.00%> (-0.01%) ⬇️
rich/style.py 99.75% <100.00%> (-0.01%) ⬇️
rich/syntax.py 99.37% <100.00%> (+0.07%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c17bf91...21b51aa. Read the comment docs.

@saulshanabrook
Copy link
Contributor Author

@willmcgugan Oh whoops! I guess I should have tested it first :)

I updated this PR to remove the code changes, but keep the tests and docs.

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

Successfully merging this pull request may close these issues.

None yet

3 participants