[Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

Peter O'Connor peter.ed.oconnor at gmail.com
Fri Apr 13 09:30:44 EDT 2018


Well this may be crazy sounding, but we could allow left or right
assignment with

name := expr
expr =: name

Although it would seem to violate the "only one obvious way" maxim, at
least it avoids this overloaded meaning with the "as" of "except" and "with"



On Fri, Apr 13, 2018 at 9:29 AM, Ethan Furman <ethan at stoneleaf.us> wrote:

> On 04/13/2018 06:18 AM, Steven D'Aprano wrote:
>
>> On Fri, Apr 13, 2018 at 09:56:35PM +1000, Chris Angelico wrote:
>>
>
> If we agree that the benefit of putting the expression first is
>> sufficiently large, or that the general Pythonic look of "expr as name"
>> is sufficiently desirable (it just looks and reads nicely), then we can
>> afford certain compromises. Namely, we can rule that:
>>
>>      except expr as name:
>>      with expr as name:
>>
>> continue to have the same meaning that they have now and never mean
>> assignment expressions. Adding parens should not change that.
>>
>
> +1
>
> In other words, the rule is that "expr as name" keeps its current, older
>> semantics in with and except statements, and NEVER means the new, PEP
>> 572 assignment expression.
>>
>> Yes, that's a special case that breaks the rules, and I accept that it
>> is a point against "as". But the Zen is a guideline, not a law of
>> physics, and I think the benefits of "as" are sufficient that even
>> losing a point it still wins.
>>
>
> +1
>
> 2) Forbid any use of "(expr as name)" in the header of a 'with' statement
>>>
>>
>> You can't forbid it, because it is currently allowed syntax (albeit
>> currently without the parens). So the rule is, it is allowed, but it
>> means what it meant pre-PEP 572.
>>
>
> +1
>
> If people agree with me that it is important to put the expression first
>> rather than the target name, then the fact that statements and for loops
>> put the name first shouldn't matter.
>>
>
> +1 to expression coming first!  ;)
>
> --
> ~Ethan~
>
>
>
> _______________________________________________
> 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/9e10606d/attachment.html>


More information about the Python-ideas mailing list