[doc] Mention with and except clauses in globals()#13232
[doc] Mention with and except clauses in globals()#13232JulienPalard merged 2 commits intopython:masterfrom
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.