[Python-ideas] Inline assignment expression

Jervis Whitley jervisau at gmail.com
Sat Mar 14 23:59:38 CET 2009


>
>> if (something as x) == other:
>>    # can now use x.
>
> Interesting. I'd definitely prefer that to the C-style inline assignment
> syntax: I think it reads better, and there's less chance of the Accidental
> Assignment Instead Of Comparison trap that has plagued other languages.

However, allowing this "something as x" syntax for assignment would cause
confusion with the "with contextmanager as x" scenario. "as" was chosen in their
case because the expr contextmanager is not assigned to x.
While I do like the "as" syntax too, I have not endorsed it for the
above reason.

However, this does show that using the "as" makes this somehow
pythonic looking,
and there must be an alternative that keeps this far enough away from the
assignment expressions in other languages so as to avoid the trap you mention.

> I remain to be convinced that inline assignment is enough of a win in
> general, but if implemented, that's the syntax I'd want.

Cheers,

Jervis



More information about the Python-ideas mailing list