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

Paul Moore p.f.moore at gmail.com
Thu Apr 12 07:09:22 EDT 2018


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 also one that I'd like to see implemented as a warning in the
common linters and style checkers.

I'm still not convinced that this whole proposal is a good thing (the
PEP 8 suggestions feel like fighting a rearguard action against
something that's inevitable but ill-advised), but if it does get
accepted it's in a lot better place now than it was when the
discussions started - so thanks for all the work you've done on
incorporating feedback.

Paul


More information about the Python-ideas mailing list