Skip to content
New issue

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

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

Already on GitHub? # to your account

Adds missing prop to __slots__ of Emoji #1364

Merged
merged 4 commits into from
Jul 25, 2021
Merged

Adds missing prop to __slots__ of Emoji #1364

merged 4 commits into from
Jul 25, 2021

Conversation

sobolevn
Copy link
Contributor

Refs python/mypy#10864

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

This prop was missing from __slots__ 🙂

There's one more thing: current __slots__ setup does not work:

>>> e = Emoji('2nd_place_medal', variant='text')
>>> e.__slots__
['name', 'style', '_char']
>>> e.__dict__
{'variant': 'text', 'a': 1, 'bb': 1}

>>> e.a = 1  # should fail, but does not
>>> e.bb = 1  # should fail, but does not

This happens due to the fact that JupiterMixin does not have __slots__ = () defined.
I can add it if you wish 🙂

@willmcgugan
Copy link
Collaborator

Good catch. Yes, please add the missing slots.

@codecov
Copy link

codecov bot commented Jul 24, 2021

Codecov Report

Merging #1364 (ae5a57e) into master (a2adbe3) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1364   +/-   ##
=======================================
  Coverage   99.78%   99.78%           
=======================================
  Files          70       70           
  Lines        6657     6657           
=======================================
  Hits         6643     6643           
  Misses         14       14           
Flag Coverage Δ
unittests 99.78% <100.00%> (ø)

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

Impacted Files Coverage Δ
rich/markdown.py 100.00% <ø> (ø)
rich/emoji.py 100.00% <100.00%> (ø)

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 2e64170...ae5a57e. Read the comment docs.

sobolevn added 2 commits July 24, 2021 22:21
I am using `[]` for consistency with other `__slots__` definitions
@sobolevn
Copy link
Contributor Author

Whitespace issues are the worst! 😒

@sobolevn
Copy link
Contributor Author

sobolevn commented Jul 25, 2021

This looks like a bug in mypy that I am going to fix soon (hopefully):

mypy -p rich --strict
rich/jupyter.py:34: error: Need type annotation for "__slots__" (hint: "__slots__: List[<type>] = ...")

In the meantime, what should I do?

  1. Add List[str] annotation
  2. Use () (my prefernce)
  3. Use type: ignore

@willmcgugan
Copy link
Collaborator

Ah, it's complaining about the empty slots? If an empty tuple works, may as well go with that...

@willmcgugan
Copy link
Collaborator

Thanks.

@willmcgugan willmcgugan merged commit f3e8184 into Textualize:master Jul 25, 2021
@sobolevn sobolevn deleted the patch-1 branch July 25, 2021 21:50
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants