Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive --py3k comprehension-escape #2130

Closed
asottile opened this issue May 21, 2018 · 6 comments
Closed

False positive --py3k comprehension-escape #2130

asottile opened this issue May 21, 2018 · 6 comments
Labels

Comments

@asottile
Copy link
Contributor

Steps to reproduce

from __future__ import print_function

y = [x for x in range(1)]

for x in range(2):
    print(x)

Current behavior

$ pylint --py3k test.py
No config file found, using default configuration
************* Module test
W:  5,10: Using a variable that was bound inside a comprehension (comprehension-escape)

---------------------------------------------------------------------
Your code has been rated at 7.50/10 (previous run: -20.00/10, +27.50)

Expected behavior

No errors

A heuristic (that I think is valid?) is that a name x is rebound after the comprehension.

pylint --version output

$ pylint --version
No config file found, using default configuration
pylint 1.9.1, 
astroid 1.6.4
Python 2.7.15 (default, May  1 2018, 16:44:08) 
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)]
@hvelarde
Copy link

@PCManticore I found another false positive: https://travis-ci.org/plonegovbr/brasil.gov.agenda/builds/391477517#L2004

this is the code: https://github.com/plonegovbr/brasil.gov.agenda/blob/2.0a1/src/brasil/gov/agenda/tests/test_setup.py#L184-L219

and a snippet:

step = [
    step for step in upgradeSteps
    if (step[0]['dest'] == ('2000',)) and (step[0]['source'] == ('1000',))]

@PCManticore
Copy link
Contributor

Hi @hvelarde With what pylint version do you get this false positive? It doesn't reproduces for me using Python 2.7 and pylint 1.9.2.

@hvelarde
Copy link

yes, it's 1.9.2 and I can reproduce the issue locally:

$ python -V
Python 2.7.14
$ grep pylint bin/pylint 
  '/home/hvelarde/.buildout/eggs/pylint-1.9.2-py2.7.egg',
from pylint import run_pylint
run_pylint()
$ bin/pylint --py3k --disable=no-absolute-import src/brasil/gov/agenda
No config file found, using default configuration
************* Module brasil.gov.agenda.utils
W: 89,48: xrange built-in referenced (xrange-builtin)
************* Module brasil.gov.agenda.content.agendadiaria
W:136,41: basestring built-in referenced (basestring-builtin)
************* Module brasil.gov.agenda.browser.ics
W:  6, 0: Module moved in Python 3 (bad-python3-import)
************* Module brasil.gov.agenda.tests.test_setup
W:189,29: Using a variable that was bound inside a comprehension (comprehension-escape)
W:196,29: Using a variable that was bound inside a comprehension (comprehension-escape)
W:203,29: Using a variable that was bound inside a comprehension (comprehension-escape)
W:212,29: Using a variable that was bound inside a comprehension (comprehension-escape)
W:219,29: Using a variable that was bound inside a comprehension (comprehension-escape)
************* Module brasil.gov.agenda.tests.test_agenda_tile
W: 83,12: Called a next() method on an object (next-method-called)

------------------------------------------------------------------
Your code has been rated at 9.96/10 (previous run: 9.97/10, -0.01)

hvelarde added a commit to plonegovbr/brasil.gov.barra that referenced this issue Jun 14, 2018
hvelarde added a commit to plonegovbr/brasil.gov.vcge that referenced this issue Jun 14, 2018
@hvelarde
Copy link

@PCManticore in fact the error is in the line after the list comprehension as you can see in the commits referenced.

@PCManticore
Copy link
Contributor

@hvelarde I see where the issue is, the fact that you're using the same variable name for the result of the comprehension and for the iteration step, which is tripping pylint.

@PCManticore PCManticore reopened this Jun 14, 2018
@PCManticore PCManticore added this to the Next bug fix release milestone Jul 3, 2018
@PCManticore PCManticore modified the milestones: Next bug fix release, Next minor release Aug 31, 2018
@PCManticore PCManticore removed this from the Next minor release milestone Sep 23, 2018
@Pierre-Sassoulas
Copy link
Member

Won't do, we removed the python3 porting mode in 2.11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants