-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
Respect ClassVar variable annotation #150
Respect ClassVar variable annotation #150
Conversation
5dc444a
to
7e638e7
Compare
Hey @viccie30, thanks for the PR! I think we need to distinguish three cases:
I think we previously handled case 3, and your PR adds support for case 1. We now just need to support case 2 🙂 WDYT? We can just check if the |
Thanks for looking into the PR. I agree that there's 3 cases. Case 1 is user error, like you say. Case 2 is already supported in this PR, through line 566 in src/griffe/agents/visitor.py. I'm not sure what you mean with case 3. According to the PEP if a non-ClassVar annotated attribute at class scope gets a value assigned at class scope, it's still an instance variable and not a class variable. This PR handles it as such. I have added new test cases to check this. |
7e638e7
to
2111759
Compare
Thanks. Well to me |
According to [PEP 526](https://peps.python.org/pep-0526/#class-and-instance-variable-annotations) annotated attributes in a class body are instance variables by default, unless explicitly overridden by using [`typing.ClassVar`](https://docs.python.org/3/library/typing.html#typing.ClassVar). Griffe also considers annotated attributes with a default value class variables.
2111759
to
688e7b0
Compare
I have added a branch in |
I've added the |
According to PEP 526 annotated attributes in a class body are instance variables by default, unless explicitly overridden by using
typing.ClassVar
.This PR makes 2 changes:
typing.ClassVar
in class variable annotations.__init__()
.