FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Handle corner case: protocol vs classvar vs descriptor by ilevkivskyi · Pull Request #19277 · python/mypy · GitHub

Repository navigation

Handle corner case: protocol vs classvar vs descriptor - #19277

Merged
ilevkivskyi merged 3 commits into
python:masterfrom
ilevkivskyi:proto-desc-classvar
Jun 13, 2025
Merged

ilevkivskyi merged 3 commits into
python:masterfrom
ilevkivskyi:proto-desc-classvar

Conversation

Copy link
Copy Markdown
Member

Ref #19274

This is a bit ugly. But I propose to have this "hot-fix" until we have a proper overhaul of instance vs class variables. To be clear: attribute access already works correctly (on both P and Type[P]), but subtyping returns false because of

                elif (IS_CLASSVAR in subflags) != (IS_CLASSVAR in superflags):
                    return False

This comment has been minimized.

JukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This looks reasonable as a short-term fix . We can continue supporting this use case, though users will have to add an explicit ClassVar annotation.

JukkaL commented Jun 11, 2025

Copy link
Copy Markdown
Collaborator

What about mentioning this in the documentation? This may be non-obvious for users.

Copy link
Copy Markdown
Member Author

Good point! I will add the docs later today.

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

ilevkivskyi merged commit 5081c59 into python:master Jun 13, 2025
ilevkivskyi deleted the proto-desc-classvar branch June 13, 2025 23:21
esarp pushed a commit that referenced this pull request Jul 3, 2025
Ref #19274

This is a bit ugly. But I propose to have this "hot-fix" until we have a
proper overhaul of instance vs class variables. To be clear: attribute
access already works correctly (on both `P` and `Type[P]`), but
subtyping returns false because of
```python
                elif (IS_CLASSVAR in subflags) != (IS_CLASSVAR in superflags):
                    return False
```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

2 participants


Back | FazBrowse Home | New Git URL