[Python-ideas] Inline assignments using "given" clauses
ncoghlan at gmail.com
Sat May 5 11:26:31 EDT 2018
On 6 May 2018 at 00:33, Mikhail V <mikhailwas at gmail.com> wrote:
> recently I have discovered interesting fact: it seems one
> can already use 'inline assignment' with current syntax. E.g.:
> if exec("m = input()") or m:
> print (m)
> It seem to work as inline assignment correctly.
> Yes it is just coincidence, BUT: this has the wanted effect!
> - hides one line in "if" and "while"
> - leaves the assignment statement (or is it expression now? ;)
> - has explicit appearance
> So we have it already?
Not really, since:
1. exec with a plain string has a very high runtime cost (the compiler is
pretty slow, since we assume the results will be cached)
2. exec'ed strings are generally opaque to static analysis tools
3. writing back to the local namespace via exec doesn't work consistently
at function scope (and assuming PEP 558 is eventually accepted, will some
day reliably *never* work)
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas