Skip to content

Fix crash on invalid redefinition in dataclass - #22095

Open
ilevkivskyi wants to merge 4 commits into
python:masterfrom
ilevkivskyi:fix-datacls-redef
Open

ilevkivskyi wants to merge 4 commits into
python:masterfrom
ilevkivskyi:fix-datacls-redef

Conversation

@ilevkivskyi

@ilevkivskyi ilevkivskyi commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

Fixes #20476

Fix seems to be quite simple: if there are some weird redefinitions, just ignore them, an error is already given.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@ilevkivskyi

Copy link
Copy Markdown
Member Author

Both errors in homeassistant are correct (inconsistent self-binding), but the error message in the first one is really confusing. I will check if it is easy to fix.

@ilevkivskyi

Copy link
Copy Markdown
Member Author

Actually, I think the second one is wrong, we should expand the self-type there.

@ilevkivskyi

Copy link
Copy Markdown
Member Author

OK, the situation is quite messy. So I will try to simply restore the existing behavior.

@github-actions

This comment has been minimized.

@ilevkivskyi

ilevkivskyi commented Oct 3, 2026 •

Copy link
Copy Markdown
Member Author

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.

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mypy crashes on a dataclass

1 participant