Skip to content

Do not treat annotated self-assign as special#20148

Open
sterliakov wants to merge 1 commit intopython:masterfrom
sterliakov:bugfix/gh-20144-final-redef
Open

Do not treat annotated self-assign as special#20148
sterliakov wants to merge 1 commit intopython:masterfrom
sterliakov:bugfix/gh-20144-final-redef

Conversation

@sterliakov
Copy link
Copy Markdown
Collaborator

@sterliakov sterliakov commented Oct 30, 2025

Fixes #20144.

Historically we have special treatment for X = X "redefinitions" in global scope. This special case was introduced in #7144, and all test cases there are unannotated.

I suspect that it was not supposed to include annotated cases at all (cc @JukkaL as the PR author - is my understanding correct?), because it skips a whole bunch of annotation checks - final, classvar, annotation sanity, plugins, etc.:

mypy/mypy/semanal.py

Lines 3269 to 3280 in 12d5da4

s.is_final_def = self.unwrap_final(s)
self.analyze_lvalues(s)
self.check_final_implicit_def(s)
self.store_final_status(s)
self.check_classvar(s)
self.process_type_annotation(s)
self.apply_dynamic_class_hook(s)
if not s.type:
self.process_module_assignment(s.lvalues, s.rvalue, s)
self.process__all__(s)
self.process__deletable__(s)
self.process__slots__(s)

@github-actions
Copy link
Copy Markdown
Contributor

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

@sterliakov sterliakov requested a review from JukkaL November 3, 2025 16:34
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.

Final not honored when applied post-hoc

1 participant