F812 fails under Python 3

Bug #1685910 reported by Peter
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Pyflakes
Invalid
Undecided
Unassigned

Bug Description

Under both Python 2 and 3, I expect the F812 warning to be reported.

I originally found this via TravisCI testing, see https://travis-ci.org/peterjc/biopython/builds/225261622 for example, before preparing this minimal test case. Originally logged against flake8 as https://gitlab.com/pycqa/flake8/issues/326

I am using pyflakes 1.5.0 installed with pip under macOS using either Apple provided Python 2.7, or a self-compiled Python 3.4.

Test script and its output:

```
$ cat test_F812.py
x = 3

y = [chr(x + 32) for x in range(3)]

print("The value of x should be 2 or 3 (matching your version of Python):")
print(x)
$ python test_F812.py
The value of x should be 2 or 3 (matching your version of Python):
2
$ python3 test_F812.py
The value of x should be 2 or 3 (matching your version of Python):
3
```

Expected output as seen on Python 2.7,

```
$ /usr/local/bin/pyflakes --version
1.5.0
$ /usr/local/bin/pyflakes test_F812.py ; echo "Return code $?"
test_F812.py:3: list comprehension redefines 'x' from line 1
Return code 1
```

or to show explicitly this is under Python 2,

```
$ python --version
Python 2.7.10
$ python -m pyflakes --version
1.5.0
$ python -m pyflakes test_F812.py ; echo "Return code $?"
test_F812.py:3: list comprehension redefines 'x' from line 1
Return code 1
```

Problem output as seen on Python 3.4,

```
$ pyflakes --version
1.5.0
$ pyflakes test_F812.py ; echo "Return code $?"
Return code 0
```

or to show explicitly this is under Python 3,

```
$ python3 --version
Python 3.4.1
$ python3 -m pyflakes --version
1.5.0
$ python3 -m pyflakes test_F812.py ; echo "Return code $?"
Return code 0
```

Revision history for this message
Ian Cordasco (icordasc) wrote :

This is the intended behaviour for PyFlakes. It has different errors that it reports based on which version of Python it's run under.

Changed in pyflakes:
status: New → Invalid
Revision history for this message
Peter (maubp) wrote :

OK, thanks for the quick clear cut reply. This surprised me - could the general principle be mentioned on the README?

https://github.com/PyCQA/pyflakes/blob/master/README.rst

If there is a table of all the pyflakes error codes in your documentation I could not find it, but it would be great to say there which are Python 2 or 3 specific.

Revision history for this message
asmeurer (asmeurer) wrote :

The codes themselves aren't specific. Pyflakes parses the code using the AST, syntax rules, and built in names for the version of Python it is running in. For instance, using "xrange" will give an undefined name warning in Python 3 but not in Python 2.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.