Re: [Python-Dev] PEP 572: Assignment Expressions

2018年4月20日 17:17:49 -0700

On Sat, Apr 21, 2018 at 8:07 AM, Mike Miller <[email protected]> wrote:
> On 2018年04月20日 14:59, Jelle Zijlstra wrote:
>> In other words, the with statement would continue to require an as
>> clause
>> outside of the parentheses. A double name binding doesn't seem very
>> useful
>> however.
>>
>> The with statement does not require an as clause.
>
> Sorry, more precisely a contenxt-manager object to be returned. So perhaps
> this "with" issue may not be one at all.
That's completely different, and isn't a syntactic point. They may
bomb with AttributeError at run time, but they also may not.
> My expectations:
>
> with open(fn) as f: # current behavior
> with (open(fn) as f): # syntax error, missing clause
> with closing(urlopen(url)) as dl: # current behavior
> with closing(urlopen(url) as dl): # syntax error, missing clause
> with (closing(urlopen(url)) as dl): # syntax error, missing clause
The second and fifth could be special cased as either the same as
first and third, or as SyntaxErrors. (But which?) The fourth one is
very tricky. If 'expr as name' is allowed inside arbitrary
expressions, why shouldn't it be allowed there? The disconnect between
viable syntax and useful statements is problematic here.
ChrisA
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to