You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Typing a class attribute as ClassVar leads to the invalid assumption that the attribute must be constant and has pylint produce invalid-name. This also happens for Supscriptions (more elaborately typed variables, e. g. ClassVar[List]).
Searching for "invalid-name" and "classvar" I find three issues - a closed one concerning Enum (#4149) and an open and a closed one concerning dataclasses (#3405, #4154). I deem them tangential.
The preview release did not solve my problem - see below.
************* Module a
a.py:7:4: C0103: Class constant name "shared_var_1" doesn't conform to UPPER_CASE naming style (invalid-name)
a.py:8:4: C0103: Class constant name "shared_var_1" doesn't conform to UPPER_CASE naming style (invalid-name)
-------------------------------------------------------------------
Your code has been rated at 6.00/10 (previous run: 10.00/10, -4.00)
Expected behavior
Mutable ClassVar should not be judged like constants and should not result in invalid-name.
Type checkers should infer a final attribute that is initialized in a class body as being a class variable. Variables should not be annotated with both ClassVar and Final.
While that makes all constants also ClassVar, ClassVar is not necessarily constant.
The preview release (pylint 3.0.0a1, other versions the same) produces the same pylint complains as 2.7.4 - invalid-name. For pylint 2.7.2 (other versions the same) there are no complains.
#4266 recently changed corresponding code. I suspect these code changes enabled actual checking for ClassVar in the first place (and work well enough for actual constants) but now lead to the problems mentioned above for non-constants.
The text was updated successfully, but these errors were encountered:
That one is one me. I confused the meaning of ClassVar and Final in a class context, but as you said: ClassVars can be mutable. I'll work on a fix for it soon.
Typing a class attribute as
ClassVar
leads to the invalid assumption that the attribute must be constant and haspylint
produceinvalid-name
. This also happens for Supscriptions (more elaborately typed variables, e. g.ClassVar[List]
).Searching for "invalid-name" and "classvar" I find three issues - a closed one concerning Enum (#4149) and an open and a closed one concerning dataclasses (#3405, #4154). I deem them tangential.
The preview release did not solve my problem - see below.
Steps to reproduce
Given a file
a.py
:Current behavior
Result of
pylint a.py
:Expected behavior
Mutable ClassVar should not be judged like constants and should not result in invalid-name.
PEP-591 states:
While that makes all constants also ClassVar, ClassVar is not necessarily constant.
pylint --version output
Result of
pylint --version
output:The preview release (pylint 3.0.0a1, other versions the same) produces the same pylint complains as 2.7.4 - invalid-name. For pylint 2.7.2 (other versions the same) there are no complains.
#4266 recently changed corresponding code. I suspect these code changes enabled actual checking for ClassVar in the first place (and work well enough for actual constants) but now lead to the problems mentioned above for non-constants.
The text was updated successfully, but these errors were encountered: