Fix crash on invalid redefinition in dataclass - #22095
ilevkivskyi wants to merge 4 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Both errors in |
|
Actually, I think the second one is wrong, we should expand the self-type there. |
|
OK, the situation is quite messy. So I will try to simply restore the existing behavior. |
This comment has been minimized.
This comment has been minimized.
|
After even more thinking, the dataclasses are different from regular classes in how they handle callables. So let's not go down this rabbit hole, and focus on simply fixing the crash. I will however keep all the tests fore future reference. |
|
Diff from mypy_primer, showing the effect of this PR on open source code: scipy-stubs (https://github.com/scipy/scipy-stubs)
- tests/misc/test_submodules_empty.pyi:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
|
| foo = "test" | ||
| foo: int = 42 # E: Name "foo" already defined on line 5 | ||
|
|
||
| reveal_type(Test) # N: Revealed type is "def () -> __main__.Test" |
There was a problem hiding this comment.
Maybe also reveal the type of attribute foo?
| class Test: | ||
| foo = fn | ||
| foo: int = 42 # E: Name "foo" already defined on line 8 | ||
| [builtins fixtures/dataclasses.pyi] |
There was a problem hiding this comment.
Maybe also reveal type of attribute foo?
Fixes #20476
Fix seems to be quite simple: if there are some weird redefinitions, just ignore them, an error is already given.