Issue 4292: 2to3 fails to convert "from something import (a, b, c)" (original) (raw)

Issue4292

Created on 2008-11-10 07:03 by certik, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
import.patch certik,2008-11-10 07:03
2to3_fix_import.py vstinner,2008-11-10 10:45 Patch fix_import.py to support "from x import (y, z)"
Messages (6)
msg75683 - (view) Author: Ondřej Čertík (certik) Date: 2008-11-10 07:03
While converting the SymPy repo: the 2to3 failed to convert stuff like: from something import (a, b, c, ) Attached find the patch that I had to do by hand -- I think 2to3 should be able to fix this as well.
msg75687 - (view) Author: Ondřej Čertík (certik) Date: 2008-11-10 09:56
Author: STINNER Victor (haypo): You would like to replace "from mptypes import ..." by "from .mptypes import ...". Is it really a bug? Python is unable to guess if mptypes, functions or settings are "global" modules or "relative" modules. Why don't you patch your original code since Python 2.5 also supports this syntax? Documentation: http://www.python.org/doc/2.5.2/ref/import.html http://docs.python.org/reference/simple_stmts.html#the-import-statement
msg75688 - (view) Author: Ondřej Čertík (certik) Date: 2008-11-10 09:58
> You would like to replace "from mptypes import ..." by "from .mptypes > import ...". Yes, exactly, see the patch where I did that. > Is it really a bug? Python is unable to guess if mptypes, > functions or settings are "global" modules or "relative" modules. I think it is a bug, because 2to3 correctly fixed all the other import statements, like "from something import a, b, c", but failed with "from something import (a, b, c)". > Why don't you patch your original code since Python 2.5 also > supports this syntax? Because we need to support python2.4, a lot of people still use it.
msg75690 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-11-10 10:45
Ooops, I replied to the wrong issue (#4292) :-p My test was wrong: yes, 2to3 needs a patch. I wrote one (with no test yet).
msg75707 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-11-10 21:31
Fixed in r67179. Ondrej, thanks for running 2to3 over sympy and finding all these tasty bugs!
msg75708 - (view) Author: Ondřej Čertík (certik) Date: 2008-11-10 22:34
Benjamin, thanks for the fantastic work! I discovered more bugs, but this time I reported to the py3000 list, as I need more feedback on it. But it seems you'll get another tasty bug for the 2to3, among other things. :)
History
Date User Action Args
2022-04-11 14:56:41 admin set github: 48542
2008-11-10 22:34:58 certik set messages: +
2008-11-10 21:31:42 benjamin.peterson set status: open -> closedresolution: fixedmessages: +
2008-11-10 17:48:25 benjamin.peterson set assignee: benjamin.petersonnosy: + benjamin.peterson
2008-11-10 10:45:17 vstinner set files: + 2to3_fix_import.pynosy: + vstinnermessages: +
2008-11-10 09:58:14 certik set messages: +
2008-11-10 09:56:05 certik set messages: +
2008-11-10 07:03:53 certik create