accept python2 print syntax in python 3 files

Bug #1541912 reported by jpinon
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Pyflakes
New
Undecided
Unassigned

Bug Description

Using pyflakes 8.1 on this code does not raise error :

import sys
print >>sys.stderr, "Hello"

Launched with :

python3 -m pyflakes hello.py

jpinon (jpinon)
description: updated
Revision history for this message
asmeurer (asmeurer) wrote :

It's valid syntax in Python 3. >> is the right shift operator, and the comma creates a tuple. If you run the code, you'll see that it raises a TypeError, not a SyntaxError. Unless pyflakes is going to do some basic operator type checking on builtins (could be a good idea?) it's not going to detect this.

Revision history for this message
John Vandenberg (jayvdb) wrote :

fwiw, flake8 plugin `hacking` emits:

H233 Python 3.x incompatible use of print operator

and `flake8-print` emits

T001 print statement found.

It seems reasonable and straight forward for pyflakes to also detect this on Python 3 only.

However, to do this right, pyflakes needs an accurate understanding of `__future__.print_function` so that the error also occurs on Python 2 when `print_function` is active. That should be fairly easy also now, as __future__ in doctest is now correctly detected (see https://github.com/pyflakes/pyflakes/commit/9c88c0ec3f4cdb0fb2e69c2bdadc0bdd03da4a55 ).

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.