Skip to content

Conversation

@fangyi-zhou
Copy link
Contributor

@fangyi-zhou fangyi-zhou commented Dec 23, 2025

Summary

This diff extends existing re-assignment checks for variables declared as Final to a few other binding constructs that are less common (namely unpacking assignments, context manager assignments, and loop variable assignments). Overall, we have 3 more passing conformance test cases.

Test Plan

python test.py

@meta-cla meta-cla bot added the cla signed label Dec 23, 2025
@fangyi-zhou fangyi-zhou changed the title Final reassignment additional checks Check re-assignment of Final variables in less-common binding constructs Dec 23, 2025
@github-actions

This comment has been minimized.

Copy link
Contributor

@yangdanny97 yangdanny97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM, but I'll wait to import till after #1923 is merged

@yangdanny97 yangdanny97 self-assigned this Dec 29, 2025
In this diff, we check for final annotations in unpacking assignments
(e.g. when LHS is a tuple or list), and raise an error if a final
variable is re-assigned.

One fewer difference for conformance tests.
In this diff, we check whether the loop variable is marked final, and
raise an error if that's the case.

One fewer difference for conformance tests.
@fangyi-zhou fangyi-zhou force-pushed the final-reassignment-additional-checks branch from 90e81b9 to 1e42a87 Compare December 29, 2025 18:33
@fangyi-zhou
Copy link
Contributor Author

Rebased

@github-actions
Copy link

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

@meta-codesync
Copy link

meta-codesync bot commented Dec 30, 2025

@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this in D89935200.

Copy link
Contributor

@kinto0 kinto0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@meta-codesync
Copy link

meta-codesync bot commented Jan 2, 2026

@yangdanny97 merged this pull request in cf29d5f.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants