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
This was clarified in the typing specification here. You can read more about the semantics of the Final special form here. While class variables are not included in the __init__ (because they shouldn't change per instance), Final (in the context of a class) means the value can't change after the class have been instantiated.
I wonder why python even includes a Final field into the __init__ 🤔
In Java for example, you can declare an attribute as Final and define it either directly on the same line, or else in the constructor. Defining the value in the constructor is very useful to be able to set the final attribute with a calculated value. It's cool Python chose to do the same, but the linters are not uptodate yet.
Using a bare
Final
special form with a default value, pyright will not assume it is a normal field (probably because it assumes it is aClassVar
?):Code sample in pyright playground
However, mypy seems to include
a
as a field (playground).Seems like the conformance tests don't cover this use case, so it might have been an oversight.
The text was updated successfully, but these errors were encountered: