[code-quality] Warn on list comprehension variables used outside list comprehensions?
Skip Montanaro
skip.montanaro at gmail.com
Wed Nov 26 15:57:24 CET 2014
> That's not the point of this check. The point of this check is that on
> Python 2, the binding to x in the comprehension bleeds outside of the
> comprehension scope
Got it.
Still, this code:
> x = 10
> [x for x in range(3)]
> print(x + 1)
will run differently in Python 2 than Python3, so even if that was a
conscious choice by the author, a --py3k flag should cause a message
for this code. This is even worse than the simpler
> [x for x in range(3)]
> print(x + 1)
because at least that will raise a NameError when run in Python 3. The
three-line construct will still run, though produce different output.
Skip
More information about the code-quality
mailing list