[issue39331] 2to3 mishandles indented imports

2020-01-17 Thread Cheryl Sabella


Cheryl Sabella  added the comment:

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

--
nosy: +cheryl.sabella
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> 2to3 Conversion Result using BlankLine() can be Syntactically 
Incorrect

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39331] 2to3 mishandles indented imports

2020-01-14 Thread Guy Galun


New submission from Guy Galun :

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 
  File "./lldbmacros/xnu.py", line 771, in 
from memory import *
  File "./lldbmacros/memory.py", line 11, in 
import macho
  File "./lldbmacros/macho.py", line 3, in 
from macholib import MachO as macho
  File "./lldbmacros/macholib/MachO.py", line 10, in 
from .mach_o import MH_FILETYPE_SHORTNAMES, LC_DYSYMTAB, LC_SYMTAB
  File "./lldbmacros/macholib/mach_o.py", line 16, in 
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.

--
components: 2to3 (2.x to 3.x conversion tool)
files: ptypes.py
messages: 359978
nosy: galun.guy
priority: normal
severity: normal
status: open
title: 2to3 mishandles indented imports
type: crash
versions: Python 3.9
Added file: https://bugs.python.org/file48839/ptypes.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com