This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: lib2to3 raises ParseError on argument called "print"
Type: behavior Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.7
Status: closed Resolution: not a bug
Dependencies: Superseder: 2to3 Parse Error on Python 3 print() with arguments
View: 35260
Assigned To: Nosy List: benjamin.peterson, martin.panter, n_rosenstein, terry.reedy, timokau
Priority: normal Keywords:

Created on 2018-12-03 10:20 by n_rosenstein, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg330926 - (view) Author: Niklas Rosenstein (n_rosenstein) * Date: 2018-12-03 10:20
On Python 3.7.0 lib2to3 will not parse code like this:

    def foo(print=None):

and yield the following error instead

    lib2to3.pgen2.parse.ParseError: bad input: type=1, value='print', context=('', (1, 8))
msg331359 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-12-07 21:51
In 2.x, 'print' is a reserved keyword and compiling foo fails with SyntaxError.  AFAIK, 2to3 expects the input to be *valid* 2.x code that compiles.  So it seems to me that the bug is in the input, not 2to3, and that this issue should be closed as 'not a bug'.
msg331374 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2018-12-08 07:05
Previous related reports:

* Issue 35260: “2to3” doesn’t parse Python 3’s “print” function by default because it is supposed to translate Python 2 syntax
* Issue 2412: “2to3” should support “from __future__ import print_function”. That frees up the “print” reserved keyword in Python 2.6+.
msg333559 - (view) Author: timokau (timokau) Date: 2019-01-13 17:39
I disagree that this is "not a bug". While conversion from 2 to 3 is 2to3's main intention, the documentation advertises:

2to3 supporting library lib2to3 is, however, a flexible and generic library, so it is possible to write your own fixers for 2to3. lib2to3 could also be adapted to custom applications in which Python code needs to be edited automatically.

And it is used for other purposes. See
- this sphinx bug:
- bower:
msg333566 - (view) Author: timokau (timokau) Date: 2019-01-13 19:49
Also `print("a", file=sys.stderr)` *is* valid python2 provided that `print_function` is imported.
Date User Action Args
2022-04-11 14:59:08adminsetgithub: 79564
2019-01-13 19:49:02timokausetmessages: + msg333566
2019-01-13 17:39:13timokausetnosy: + timokau
messages: + msg333559
2018-12-08 07:05:02martin.pantersetstatus: open -> closed

superseder: 2to3 Parse Error on Python 3 print() with arguments

nosy: + martin.panter
messages: + msg331374
resolution: not a bug
stage: resolved
2018-12-07 21:51:29terry.reedysetnosy: + terry.reedy, benjamin.peterson
messages: + msg331359
2018-12-03 10:20:07n_rosensteincreate