Round 2 (Changed order, see below):
1. with open(fn) as f: # current behavior
2. with (open(fn) as f): # same
3. with closing(urlopen(url)) as dl: # current behavior
5. with (closing(urlopen(url)) as dl): # same
4. with closing(urlopen(url) as dl): # urlopener named early
On 2018-04-20 17:15, Chris Angelico wrote:
The second and fifth could be special cased as either the same as
first and third, or as SyntaxErrors. (But which?)
If they are expressions, they should be the same once evaluated, no?
(I had a brief episode where I wrote that "as" was required with "with", instead
of the CM object, sorry. :)
The fourth one is very tricky. If 'expr as name' is allowed inside arbitrary
expressions, why shouldn't it be allowed there?
Yes, they should be allowed there.
The disconnect between viable syntax and useful statements is problematic here.
Number 4 appears to name the urlopener early. Since closing() returns it as
well, might it work anyway?
Might be missing something else, but #4 looks like a mistake with the layout of
the parentheses, which can happen anywhere. I don't get the sense it will
happen often.
Cheers,
-Mike
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com