Replies: 1 comment
-
PEP 557, which introduced dataclasses, isn't clear on the intended behavior here. Nor is the typing spec. I don't think it's a good idea to change pyright's behavior unless/until the intended behavior is clarified in the typing spec. If you're interested in spearheading a change in the typing spec, here is the process that the typing council (of which I'm a member) has established: https://github.com/python/typing-council#decisions. If/when there is consensus on the intended behavior and the typing spec has been changed accordingly, then we can introduce conformance tests for the behavior, and you all Python type checkers (including pyright) will likely adopt that behavior. |
Beta Was this translation helpful? Give feedback.
-
According to the docs on type qualifiers (specifically the
ImmutablePoint
example), attributes annotated withFinal
within class body are interpreted as:__init__
.Considering following definition:
In both cases an error is rightfully reported, but the resulting message reveals the assignment of
= field()
makes pyright treat thebar
attribute as aClassVar
. Also the mention of__set__
is weird.(This is on pylance
v2024.2.103 (pre-release)
)Since assignment to fields is used to give them a default value, or to customize them via the
field()
function, andFinal
fields within dataclass-likes become normal instance attributes (unlikeClassVar
s, which do not become fields), I believe it makes sense to treatFinal
attributes in dataclass-likes as instance-level constants, despite the assignment to them.P.S. it seems that pyright/pylance does not treat the
dataclasses
module right within jupyter notebooks. I'll file an issue on that later.Beta Was this translation helpful? Give feedback.
All reactions