-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
[doc] Mention with and except clauses in globals() #13232
[doc] Mention with and except clauses in globals() #13232
Conversation
I just tested: >>> bar = 42
>>> def foo():
... global bar
... with open("/etc/hosts") as bar:
... ...
...
>>> foo()
>>> bar
<_io.TextIOWrapper name='/etc/hosts' mode='r' encoding='UTF-8'> and it works, so I'd say the proposed modification is wrong? |
@JulienPalard I believe for/class/def behave exactly the same, that part of the documentation refers to global being written after those statements. Compare this:
In all cases, _before works, but _after fails. So does with "with" and "except". |
@JulienPalard I have verified for/class/def/with/except behave in the same way. These are the examples I have run: forDoesn't fail
Fails
classDoesn't fail
Fails
defDoesn't fail
Fails
withDoesn't fail
Fails
exceptDoesn't fail
Fails
|
@JulienPalard any chance you can take a look at this? If so, please see my previous comment. |
Thanks @andresdelfino ! TIL global behave differently if placed after þ |
@JulienPalard What's "þ"? My guess is that you wrote something that GitHub decided to parse :P |
@andresdelfino it's my way to write :P (I do it using a compose key) |
Also changed "loop control target" to "target list", as that's the actual term used by for's grammar.
The long line is intentional. If the PR is approved I'll add the line breaks.