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

Chris Angelico rosuav at gmail.com
Thu Apr 12 09:08:06 EDT 2018


On Thu, Apr 12, 2018 at 9:09 PM, Paul Moore <p.f.moore at gmail.com> wrote:
> On 11 April 2018 at 22:28, Chris Angelico <rosuav at gmail.com> wrote:
>> On Thu, Apr 12, 2018 at 1:22 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>>> This argument will be strengthened by making the examples used in the
>>> PEP itself more attractive, as well as proposing suitable additions to
>>> PEP 8, such as:
>>>
>>> 1. If either assignment statements or assignment expressions can be
>>> used, prefer statements
>>> 2. If using assignment expressions would lead to ambiguity about
>>> execution order, restructure to use statements instead
>>
>> Fair enough. Also adding that chained assignment expressions should
>> generally be avoided.
>
> Another one I think should be included (I'm a bit sad that it's not so
> obvious that no-one would ever even think of it, but the current
> discussion pretty much killed that hope for me).
>
> * Assignment expressions should never be used standalone - assignment
> statements should *always* be used in that case.

That's covered by the first point. If it's a standalone statement,
then the statement form could be used, ergo you should prefer the
statement form.

ChrisA


More information about the Python-ideas mailing list