8000 Clarifying nonlocal doc: SyntaxError is raised if nearest enclosing scope is global by quazi-irfan · Pull Request #114009 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Clarifying nonlocal doc: SyntaxError is raised if nearest enclosing scope is global #114009

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

Merged
Prev Previous commit
Next Next commit
Move lines to top and minor changed to improve readability
  • Loading branch information
quazi-irfan committed Mar 15, 2024
commit 069c0963513b135e45c84ffdb6c2ae6015ab4733
10 changes: 5 additions & 5 deletions Doc/reference/executionmodel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ determined by scanning the entire text of the block for name binding operations.
See :ref:`the FAQ entry on UnboundLocalError <faq-unboundlocalerror>`
for examples.

If the :keyword:`global` statement occurs within a block, all uses of the names
The :keyword:`!global` statement must precede all uses of the listed names.
If the global statement occurs within a block, all uses of the names
specified in the statement refer to the bindings of those names in the top-level
namespace. Names are resolved in the top-level namespace by searching the
global namespace, i.e. the namespace of the module containing the code block,
global namespace, the namespace of the module containing the code block,
Copy link
Member

Choose a reason for hiding this comment

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

Removing "i.e." makes this wrong: the global namespace is the same as the module namespace here.

Copy link
8000
Contributor Author

Choose a reason for hiding this comment

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

That's what I am implying here. The next part of the sentence is written in the same way.

"the builtins namespace, the namespace of the module builtins" implying the builtins namespace and the namespace of the module builtins are the same.

Copy link
Member

Choose a reason for hiding this comment

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

I see; I don't think that is clear on reading the sentence.

Copy link
Contributor Author
@quazi-irfan quazi-irfan Mar 16, 2024

Choose a reason for hiding this comment

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

How about this version of the sentence?

"Names are resolved in the top-level namespace by searching the global namespace which is the namespace of the module containing the code block, and the builtins namespace which is the namespace of the module builtins."

Doc also uses the word "module namespace" frequently.

Copy link
Member

Choose a reason for hiding this comment

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

That works though I'd put commas before "which". I think the existing wording is fine though, so I'd prefer to keep it.

Copy link
Contributor Author
@quazi-irfan quazi-irfan Mar 16, 2024

Choose a reason for hiding this comment

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

Reverted it.

I think, both of us needing a secondary clarification is a sign that this sentence could be written better.

and the builtins namespace, the namespace of the module :mod:`builtins`. The
global namespace is searched first. If the names are not found there, the
builtins namespace is searched. A new variable is created in the global
namespace if the name is also not found in the builtins namespace. The
:keyword:`!global` statement must precede all uses of the listed names.
builtins namespace is searched next. If the names are also not found in the
builtins namespace, new variables are created in the global namespace.

The :keyword:`global` statement has the same scope as a name binding operation
in the same block. If the nearest enclosing scope for a free variable contains
Expand Down
0