Skip to content

Fix redefinition logic for InitVar - #22352

Merged
hauntsaninja merged 1 commit into
python:masterfrom
ilevkivskyi:better-init-var
Nov 3, 2026
Merged

hauntsaninja merged 1 commit into
python:masterfrom
ilevkivskyi:better-init-var

Conversation

@ilevkivskyi

Copy link
Copy Markdown
Member

I know this is somewhat pedantic, but I cannot sleep well knowing we have this in our code. Few things here:

  • Everywhere else in mypy first definition wins, not the last one, so we should do the same in presence of InitVar.
  • Sorting strings is incorrect anyway, as it will put foo-redefinition-10 before foo-redefinition-9.
  • Limit this special-case only to classes explicitly touched by plugins (as indicated by non-trivial metadata)

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@hauntsaninja
hauntsaninja merged commit 1fa74ff into python:master Nov 3, 2026
25 checks passed
@ilevkivskyi
ilevkivskyi deleted the better-init-var branch November 3, 2026 10:36
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.

2 participants