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
Protocol incompatibility with Final class variable #17175
Comments
I think mypy is correct here. Pyright also generates the same errors as mypy in this case. A |
Thank you for the answer. So it seems that it's not currently possible.
when it is not, it's a class variable. Isn't that a bug? |
The protocol defines So I understand why you would find the error message somewhat confusing, but it's consistent with the way protocols are defined to work. |
I see, thank you. |
Bug Report
Given a protocol with just a read-only property, mypy allows it to bind to a class with that property declared as a
ClassVar
, but not with it declared asFinal
.To Reproduce
I also tested the following code in pyright, and it exhibits the same behavior.
Expected Behavior
If I understand correctly, Proto should be able to bind to any object
obj
such thatobj._fields
is an expression of typetuple[str, ...]
.Type1
, ...,Type4
all satisfy this requirement, but onlyType1
binds to Proto as expected.Actual Behavior
Mypy says that
_fields
is an instance variable forType2
,Type3
andType4
, but just below I can access it from the class just fine and no error is reported.pyright gives somewhat similar results, so I wonder if I'm missing something.
Your Environment
--strict
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: