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.

classification
Title: 2to3 Parse Error on Python 3 print() with arguments
Type: behavior Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: batterystaple456, mark.dickinson
Priority: normal Keywords:

Created on 2018-11-15 21:09 by batterystaple456, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg329966 - (view) Author: (batterystaple456) Date: 2018-11-15 21:09
File a.py:

------------------------------------
print("foo", end='bar') # ParseError
------------------------------------

I think the error is caused by arguments in the Python 3 print() function (e.g. end, sep) that are not ignored by 2to3, and (possibly) treated like Python 2 code.

Console stuff:

---------------------------------------------------
$ pip install 2to3
Requirement already satisfied: 2to3 in .\python37\lib\site-packages (1.0)

$ 2to3 .\a.py
...
RefactoringTool: Can't parse .\a.py: ParseError: bad input: type=22, value='=', context=('', (1, 16))
...
---------------------------------------------------
msg329986 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2018-11-16 11:22
I'm not sure I understand the report: 2to3 expects a valid Python 2 file as input, and the file a.py isn't a valid Python 2 file: the `print` line is a SyntaxError in the absence of a `from __future__ import print_function`.

So yes, this *is* being treated like Python 2 code, but that's what 2to3 is designed to do.

Can you say what you expected to happen here?
msg329988 - (view) Author: (batterystaple456) Date: 2018-11-16 11:40
I was expecting that like other Python 3 code, since it is already in Python 3, it would not parse it like Python 2.
msg329992 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2018-11-16 13:03
I'm still confused: the main purpose of 2to3 is to take Python 2 code and turn it into Python 3 code. The docs[1] are fairly unambiguous here:

> 2to3 is a Python program that reads Python 2.x source code and applies a series of fixers to transform it into valid Python 3.x code.

So expecting 2to3 *not* to parse code as though it's Python 2 code seem odd.

[1] https://docs.python.org/3.7/library/2to3.html
msg329993 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2018-11-16 13:04
Closing. 2to3 is working as designed here.
History
Date User Action Args
2022-04-11 14:59:08adminsetgithub: 79441
2018-12-08 07:05:02martin.panterlinkissue35383 superseder
2018-11-16 13:04:44mark.dickinsonsetstatus: open -> closed
resolution: not a bug
messages: + msg329993

stage: resolved
2018-11-16 13:03:13mark.dickinsonsetmessages: + msg329992
2018-11-16 11:40:52batterystaple456setmessages: + msg329988
2018-11-16 11:22:39mark.dickinsonsetnosy: + mark.dickinson
messages: + msg329986
2018-11-15 22:28:41batterystaple456settype: compile error -> behavior
2018-11-15 21:09:43batterystaple456create