List comprehensions and Python 3

I'm slowly implementing changes in our add-ons to make them Python 3 compatible using the --py3k parameter of Pylint.

on a recent automatic CI build in Travis I got the following error:

$ bin/pylint --py3k --disable=no-absolute-import src/collective/fingerpointing
No config file found, using default configuration
************* Module collective.fingerpointing.tests.test_upgrades
W: 85,17: Using a variable that was bound inside a comprehension (comprehension-escape)
W: 85,45: Using a variable that was bound inside a comprehension (comprehension-escape)
-------------------------------------------------------------------
Your code has been rated at 9.98/10 (previous run: 10.00/10, -0.02)

the code looks like this:

I manually tested it under Python 3 and I found no errors: besides that, a similar code is being used some lines above with no warnings.

according to Pylint this warning is:

Emitted when using a variable, that was bound in a comprehension handler, outside of the comprehension itself. On Python 3 these variables will be deleted outside of the comprehension.

which, IMO, is not the case.

may I just ignore this warning?

Agree, this is not the case..

Can you test pylint changing this part of the code without the if statement inside to see if this is the problem?

I think this is a false positive; as mentioned above the same code is used before with no errors. I opened a new issue:

UPDATE: Pylint's maintainer just confirmed this is a false positive.

1 Like