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

David Mertz mertz at gnosis.cx
Thu Apr 12 23:22:02 EDT 2018


Yes, I should have added ternary expressions to if statements. I can
definitely see the use there.

However, your example is not null checking. You'd have to modify it
slightly to get that:

None if var:= function() is None else var.method()

Still not bad looking.

On Thu, Apr 12, 2018, 11:01 PM Thautwarm Zhao <yaoxiansamma at gmail.com>
wrote:

>
> > You're looking at a very early commit there. I suggest looking at the
> > most recent commits on one of two branches:
>
>
> https://github.com/Rosuav/cpython/blob/statement-local-variables/Grammar/Grammar
>
> https://github.com/Rosuav/cpython/blob/assignment-expressions/Grammar/Grammar
>
> > Those are the two most recent states in my progress towards (a)
> > statement-local name bindings with "EXPR as NAME", and (b) assignment
> > expressions with "target := value".
>
> Okay, and the syntax "target := value" seems to be much easier to handle
> with.
>
> I do support this feature, but now I'm worried about the meaning of ':=',
> it seems to be a lazy assignment in some degree. I'm not sure using ':=' is
> proper here.
>
>
> > Inasmuch as I might like assignment expressions, it would only be in
> while or if statements, personally.
>
> Not exactly, assignment expression also works for "if expression", we can
> now have null checking.
>
>     var.method() if var:= function() else None
>
> Null checking is importance enough to have a specific syntax in many other
> languages(C#, kotlin, Ruby and so on), and we can even have more than null
> checking by adding expression assignment.
>
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180413/4aa790af/attachment-0001.html>


More information about the Python-ideas mailing list