Title: 2to3 Conversion Result using BlankLine() can be Syntactically Incorrect
Type: enhancement Stage: patch review
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Samuel Tatasurya, benjamin.peterson
Priority: normal Keywords: patch

Created on 2019-11-04 07:12 by Samuel Tatasurya, last changed 2019-11-09 05:52 by python-dev.

Pull Requests
URL Status Linked Edit
PR 17096 open python-dev, 2019-11-09 05:52
Messages (1)
msg355926 - (view) Author: Samuel Tatasurya (Samuel Tatasurya) Date: 2019-11-04 07:12
Transformation performed by certain fixers (e.g. future, itertools_imports) that causes a statement to be replaced by a blank line will generate a Python file that contains syntax error.

For example, assuming a Python file ( containing line below:

    from itertools import imap
except ImportError:

If we run "itertools_imports" fixer against it:
2to3 -f itertools_imports

will result in the following:


except ImportError:

which is syntactically incorrect.

Instead of always replacing such case with BlankLine(), a check should be performed beforehand if the statement to be replaced has any siblings. If no sibling is found, then replace that statement with a "pass" statement instead.

By doing this, Python source files generated by 2to3 are more readily runnable right after the transformation.
Date User Action Args
2020-01-18 03:15:58cheryl.sabellalinkissue39331 superseder
2019-11-09 05:52:30python-devsetkeywords: + patch
stage: patch review
pull_requests: + pull_request16602
2019-11-08 23:31:00terry.reedysetnosy: + benjamin.peterson
2019-11-04 07:12:47Samuel Tatasuryacreate