Skip to content

Handle corner case: protocol vs classvar vs descriptor #19277

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ilevkivskyi
Copy link
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

Copy link
Contributor

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

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

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
Copy link
Collaborator

JukkaL commented Jun 11, 2025

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

@ilevkivskyi
Copy link
Member Author

Good point! I will add the docs later today.

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