Final class variable in dataclass breaks __init__ signature #9550
Labels
addressed in next version
Issue is fixed and will appear in next published version
bug
Something isn't working
Describe the bug
Python 3.13 allows
ClassVar[Final[<type>]]
annotations for dataclass fields. Pyright 1.1.390 accepts the annotation but gets the__init__()
signature wrong.When a dataclass field is annotated as
ClassVar[Final[<type>]]
it is not added as parameter to the generated__init__()
method. The dataclass below has a final class variablebar
with a default value followed by an instance variablebaz
without default value. Python 3.13 accepts this code and generates a method__init__(self, baz)
as expected.Pyright 1.1.390 seems to parse
bar
as a regular field and therefore:baz
because it comes after a field with a default value__init__(self, bar = 0, baz)
Code or Screenshots
Additional info
This passes Pyright but forgoes the
Final
annotation:This still gets the wrong signature:
So does this:
As noted in #8676 (comment) the Python 3.13.0 implementation does not treat dataclass fields annotated
Final[ClassVar[<type>]]
as class variables. As a result, Pyright is correct here:VS Code extension or command-line
Command-line, Python 3.13.0, Pyright 1.1.390
The text was updated successfully, but these errors were encountered: