Skip to content

Conversation

fangyi-zhou
Copy link
Contributor

@fangyi-zhou fangyi-zhou commented Sep 1, 2025

Fixes #264.

This diff addresses the scoping issues of class fields in nested scopes.

When a class field is defined in a class body, the scope of the field should only be available in the immediate class block, unless for annotations. This is described in the Python doc at https://docs.python.org/3/reference/executionmodel.html#resolution-of-names

To address this issue, we check the flow style when looking up a variable. If the variable is defined as a class field, we apply appropriate checks to avoid the incorrect scoping rule from being applied.

Fixes facebook#264.

This diff addresses the scoping issues of class fields in nested scopes.

When a class field is defined in a class body, the scope of the field
should only be available in the immediate class block, unless for
annotations. This is reflected in the Python doc in
https://docs.python.org/3/reference/executionmodel.html#resolution-of-names

To address this issu, we check the flow style when looking up a
variable. If the variable is defined as a class field, we apply
appropriate checks to avoid the incorrect scoping rule from being
applied.
@meta-cla meta-cla bot added the cla signed label Sep 1, 2025
@facebook-github-bot
Copy link
Contributor

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

Copy link
Contributor

@migeed-z migeed-z 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.

@facebook-github-bot
Copy link
Contributor

@yangdanny97 merged this pull request in 2ef5a54.

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.

Class definition bindings should not be visible in nested scopes
3 participants