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 mishandles indented imports #83512

Closed
galunguy mannequin opened this issue Jan 14, 2020 · 2 comments
Closed

2to3 mishandles indented imports #83512

galunguy mannequin opened this issue Jan 14, 2020 · 2 comments
Labels
3.9 only security fixes topic-2to3 type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@galunguy
Copy link
Mannequin

galunguy mannequin commented Jan 14, 2020

BPO 39331
Nosy @csabella
Superseder
  • bpo-38681: 2to3 Conversion Result using BlankLine() can be Syntactically Incorrect
  • Files
  • ptypes.py
  • 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 2020-01-18.03:15:58.085>
    created_at = <Date 2020-01-14.15:47:38.329>
    labels = ['expert-2to3', '3.9', 'type-crash']
    title = '2to3 mishandles indented imports'
    updated_at = <Date 2020-01-18.03:15:58.082>
    user = 'https://bugs.python.org/galunguy'

    bugs.python.org fields:

    activity = <Date 2020-01-18.03:15:58.082>
    actor = 'cheryl.sabella'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-01-18.03:15:58.085>
    closer = 'cheryl.sabella'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2020-01-14.15:47:38.329>
    creator = 'galun.guy'
    dependencies = []
    files = ['48839']
    hgrepos = []
    issue_num = 39331
    keywords = []
    message_count = 2.0
    messages = ['359978', '360230']
    nosy_count = 2.0
    nosy_names = ['cheryl.sabella', 'galun.guy']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '38681'
    type = 'crash'
    url = 'https://bugs.python.org/issue39331'
    versions = ['Python 3.9']

    @galunguy
    Copy link
    Mannequin Author

    galunguy mannequin commented Jan 14, 2020

    When encountering an import that should be removed in Python 3 (e.g. "from itertools import izip"), 2to3 changes it a blank line, which may cause a runtime error if that import was indented:

    error: module importing failed: expected an indented block (ptypes.py, line 10)
    File "temp.py", line 1, in <module>
    File "./lldbmacros/xnu.py", line 771, in <module>
    from memory import *
    File "./lldbmacros/memory.py", line 11, in <module>
    import macho
    File "./lldbmacros/macho.py", line 3, in <module>
    from macholib import MachO as macho
    File "./lldbmacros/macholib/MachO.py", line 10, in <module>
    from .mach_o import MH_FILETYPE_SHORTNAMES, LC_DYSYMTAB, LC_SYMTAB
    File "./lldbmacros/macholib/mach_o.py", line 16, in <module>
    from macholib.ptypes import p_uint32, p_uint64, Structure, p_long, pypackable

    Relevant section before 2to3:

    try:
    from itertools import izip, imap
    except ImportError:
    izip, imap = zip, map
    from itertools import chain, starmap

    And after 2to3:

    try:

    except ImportError:
    izip, imap = zip, map
    from itertools import chain, starmap

    • Side note:
      This specific case may only be problematic with scripts that are partially aware of Python 3, otherwise they wouldn't try-catch that import.

    • Proposed solution:
      In case of that kind of import being the single line of an indented block, change it to "pass" instead of a blank line.

    @galunguy galunguy mannequin added 3.9 only security fixes topic-2to3 type-crash A hard crash of the interpreter, possibly with a core dump labels Jan 14, 2020
    @csabella
    Copy link
    Contributor

    Thank you for the report. This is a duplicate of bpo-38681.

    @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-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant