-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Several dataclass crashes involving Final attributes #10090
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
Labels
Comments
The same problem occurs for this snippet: from dataclasses import dataclass
from typing import Final
@dataclass
class A:
x: Final = "a"
@dataclass # Removing this decorator makes it work
class B:
y: Final = A()
|
Another occurrence of this problem with just a single dataclass: from dataclasses import dataclass
from typing import Final
def f():
@dataclass
class A:
x: Final = "a"
|
Another variant: from dataclasses import dataclass
from http import HTTPStatus
from typing import Final
@dataclass
class MyResponse:
status_code: Final = HTTPStatus.NOT_FOUND
|
This still crashes on master, but the traceback is now different following #12762. Running mypy on the original repro now produces:
|
Yet another repro for this crash was identified by @DetachHead in #13377, which I just closed as a duplicate of this issue: from dataclasses import dataclass, field
from typing import Final
@dataclass
class Foo:
a: Final = field(default=1) |
ilevkivskyi
added a commit
that referenced
this issue
Aug 27, 2022
Fixes #10090 Unfortunately we cannot fully support this use case. Mypy requires explicit type annotations to generate methods for dataclasses before type checking. While type inference for bare `Final` happens during type checking. I still try to infer type if the default is a literal, otherwise give an error, and use `Any` for generated methods.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Crash Report
I was just trying things out and found a crash with:
Note: I don't think this code is very usable. I think I would want
ClassVar
here (or just a module-scoped variable), but thought the report might be interesting all the same.Traceback
Traceback on current master:
Traceback on pip package:
To Reproduce
Run
mypy
over a file containing the content above.Your Environment
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: