[Python-ideas] Inline assignment expression

Jervis Whitley jervisau at gmail.com
Sat Mar 14 23:52:06 CET 2009


> why don't we use the same syntax as C, C++, Java, JavaScript etc.?

I have deliberately chosen to use a different syntax (right assignment
for one, and
a different, albeit nominal, operator) than C, C++ to address the
concern that a user may unintentionally assign when they wanted to compare.

http://bugs.python.org/issue1714448 the issue that I was responding to,
also recognised the need to move away from a C style assignment for a
similar situation (I have also written a patch, not posted yet, to
address their situation.)

> But I left this out intentionally for a reason. We would need to have
> a great deal of evidence that it was a mistake for making a U-turn.

I realise that this is a trivial (to implement) patch and that it must
have been left
out of Python for a reason, however I am sure that using an explicit
and elegant
enough syntax that this can shake the feeling that it is un-pythonic.

I have drafted a PEP with some of the basic discussion included and
some example situations. It does however, fail to discuss issues of
precedence and implementations
in other languages at this stage.

As implemented the precedence for this operation is just below a
BoolOp and above a BinOp

so things like

    test() as x == answer

should work and (for example)

    4 * 4 as x == 16 # True


I read your answer as a -0.5, if it is dead in the water, let me know
we can close the
Issue as a 'Wont Fix'.

Cheers,

Jervis



More information about the Python-ideas mailing list