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

Kirill Balunov kirillbalunov at gmail.com
Thu Apr 12 07:28:21 EDT 2018


2018-04-12 12:48 GMT+03:00 Jacco van Dorp <j.van.dorp at deonet.nl>:

> 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 ?)
>
>
Thank you Jacob! I do not know if I understood correctly how you understand
what is happening here. But you are just demonstrating my fears about this
proposal...

with f  := open(filename):

This will be only valid if the returned object of (f := open(filename)) defines
__enter__ and __exit__ methods ( Nevertheless, in this situation it is so).
But in other cases it will raise an error. Generally  `with name  := expr` is
not equivalent to `with expr as name:`. In another places, for example,
`except` clause `f := something` is valid only if the returned type is an
object, which inherit from BaseException. So in this two situations, in my
opinion, it will not be used too much.

Yours example under current proposal should look like  `with open(
full_file_path := os.path.join(path, filename) ) as f:`.

With kind regards,
-gdg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180412/d4aa6929/attachment.html>


More information about the Python-ideas mailing list