Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2to3 Conversion Result using BlankLine() can be Syntactically Incorrect #82862

Closed
SamuelTatasurya mannequin opened this issue Nov 4, 2019 · 1 comment
Closed

2to3 Conversion Result using BlankLine() can be Syntactically Incorrect #82862

SamuelTatasurya mannequin opened this issue Nov 4, 2019 · 1 comment
Labels
3.9 only security fixes topic-2to3 type-feature A feature request or enhancement

Comments

@SamuelTatasurya
Copy link
Mannequin

SamuelTatasurya mannequin commented Nov 4, 2019

BPO 38681
Nosy @benjaminp
PRs
  • bpo-38681: Enhance 2to3 conversion for blank line #17096
  • Superseder
  • bpo-45544: Close 2to3 issues and list them here
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-10-20.22:56:56.498>
    created_at = <Date 2019-11-04.07:12:47.801>
    labels = ['type-feature', 'expert-2to3', '3.9']
    title = '2to3 Conversion Result using BlankLine() can be Syntactically Incorrect'
    updated_at = <Date 2021-10-20.22:56:56.497>
    user = 'https://bugs.python.org/SamuelTatasurya'

    bugs.python.org fields:

    activity = <Date 2021-10-20.22:56:56.497>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-10-20.22:56:56.498>
    closer = 'iritkatriel'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2019-11-04.07:12:47.801>
    creator = 'Samuel Tatasurya'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 38681
    keywords = ['patch']
    message_count = 1.0
    messages = ['355926']
    nosy_count = 2.0
    nosy_names = ['benjamin.peterson', 'Samuel Tatasurya']
    pr_nums = ['17096']
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = '45544'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue38681'
    versions = ['Python 3.9']

    @SamuelTatasurya
    Copy link
    Mannequin Author

    SamuelTatasurya mannequin commented Nov 4, 2019

    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 (foo.py) containing line below:

    try:
    from itertools import imap
    except ImportError:
    pass

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

    will result in the following:

    try:

    except ImportError:
        pass

    which is syntactically incorrect.

    Suggestion:
    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.

    @SamuelTatasurya SamuelTatasurya mannequin added 3.9 only security fixes topic-2to3 type-feature A feature request or enhancement labels Nov 4, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes topic-2to3 type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant