Skip to content

gh-56374: Clarify nonlocal scope definition #31551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

slateny
Copy link
Contributor

@slateny slateny commented Feb 24, 2022

New comment to include this behavior:

def f():
    x = 1
    class T:
        nonlocal x
        x = 2
    T()
    print(x)
f()

prints 2

https://bugs.python.org/issue12165

@slateny slateny changed the title bpo-12165: Expanded on nonlocal scope definition bpo-12165: Expand on nonlocal scope definition Mar 4, 2022
@slateny slateny marked this pull request as draft April 19, 2022 04:36
@MaxwellDupre
Copy link
Contributor

How about adding the code above to the Docs, its a good example which all but especially non-english readers will find useful.

@slateny
Copy link
Contributor Author

slateny commented May 14, 2022

https://docs.python.org/3/tutorial/classes.html#scopes-and-namespaces-example already has an example, so instead a link to that would be a good idea I think.

@slateny slateny changed the title bpo-12165: Expand on nonlocal scope definition gh-56374: Expand nonlocal scope definition Dec 10, 2022
@slateny slateny changed the title gh-56374: Expand nonlocal scope definition gh-56374: Clarify nonlocal scope definition Dec 10, 2022
@python-cla-bot
Copy link

The following commit authors need to sign the Contributor License Agreement:

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

7 participants