-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-dataclassestopic-runtime-semanticsmypy doesn't model runtime semantics correctlymypy doesn't model runtime semantics correctly
Description
Bug Report
I wrote a code that reads the default value of an InitVar
field of a dataclass and got attr-defined
error from mypy==1.18.2. But cpython==3.13.3,3.12.10 does run without error and I believe it is reasonable to assume one can read default values from InitVar
fields reading the reference.
To Reproduce
import dataclasses
@dataclasses.dataclass
class Foo:
foo: int = 42
bar: dataclasses.InitVar[int] = 42
print(Foo.foo)
print(Foo.bar)
Expected Behavior
no-error
Actual Behavior
<string>:12: error: "type[Foo]" has no attribute "bar" [attr-defined]
Your Environment
- Mypy version used: 1.18.2, 1.17.1
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini
(and other config files): none - Python version used: 3.13.3, 3.12.10
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-dataclassestopic-runtime-semanticsmypy doesn't model runtime semantics correctlymypy doesn't model runtime semantics correctly