[Python-ideas] PEP 572: Assignment Expressions (post #4)

Jacco van Dorp j.van.dorp at deonet.nl
Thu Apr 12 05:48:28 EDT 2018


Wouldn't these local name bindings make the current "as" clause of
"with f(x) as y" completely obsolete ?

It's probably good to know my background, and my background is that I
know completely nothing of the implementation, im only junior software
engineer, and python was my first programming experience, and still
the one I have by far the most experience with.

To me, the entire proposal sounds mostly like an expansion of the as
syntax as we know it from "with". There will be no difference between:

with open(filename) as f:
    // code

and

with f  := open(filename):
    // code

or at least as far as I can see. (that is, if := will be allowed in
the with statement, and it sounds like it will ?)

from this (outsiders?) point of view, it'd make a lot more sense to
keep using "as" as the local binding operator - that's exactly what it
already seems to do, even if it looks different under the hood.
This would keep it to just one way to do stuff, and that happens to be
the way everyone's used to.

of course, should still extend. So right now.

with open(os.path.join(path, filename) as full_file_path) as f:
    // Do stuff with both full_file_path and f

wont work, but it'd still be awesome/useful if it did. (overall +1 for
the idea, for what it's worth)

Jacco


More information about the Python-ideas mailing list