[Python-Dev] PEP 572: Assignment Expressions

Mike Miller python-dev at mgmiller.net
Sun Apr 22 18:20:49 EDT 2018


On 2018-04-22 14:33, Chris Angelico wrote:
> with open(fn) as f:
> with (open(fn) as f):
> 
> These two do the same thing, but only because a file object's
> __enter__ returns self. So it's dangerous, because it WILL work... and
> people will get into the habit of parenthesizing to permit a 'with'
> statement to go across line breaks. And then they'll use a different
> context manager, like closing(), or a PsycoPG2 database connection (I
> think), where it returns something else. And it'll work, until they go
> over multiple lines, and then suddenly the semantics change.


Why do you think folks will be rushing to parenthesize with statements when it 
has always been a syntax error, there is years of code and docs that show 
otherwise, no use cases, and will take years for 3.8 to trickle out?

Seems remote, and there are mitigations that could be done.

Again it's back to "people could write bad code," but they already can with only 
+/* and ().

-Mike


More information about the Python-Dev mailing list