Discussion:
edge case
Mike Dewhirst
2014-02-14 22:57:36 UTC
Permalink
While porting a project - all modules at once - futurize threw a
traceback without contextual clues for which of my modules it found
problematic.

Traceback (most recent call last):
... (snipped)
File
"c:\users\miked\env\xxdx\lib\site-packages\libfuturize\fixer_util.py",
line 373, in check_future_import
assert 0, "strange import"
AssertionError: strange import


Rather than start again one module at a time I rummaged around line 373
in fixer_util.py to see what it was trying to do.


I hacked it as follows:

---
C:/users/miked/env/xxdx/Lib/site-packages/libfuturize/fixer_util.py~ Sat
Feb 15 09:33:01 2014
+++ C:/users/miked/env/xxdx/Lib/site-packages/libfuturize/fixer_util.py
Sat Feb 15 09:33:17 2014
@@ -341,6 +341,7 @@ def check_future_import(node):
"""If this is a future import, return set of symbols that are
imported,
else return None."""
# node should be the import statement here
+ savenode = node
if not (node.type == syms.simple_stmt and node.children):
return set()
node = node.children[0]
@@ -370,6 +371,6 @@ def check_future_import(node):
elif node.type == token.NAME:
return set([node.value])
else:
- assert 0, "strange import"
+ assert 0, "strange import: %s" % savenode

Then I ran futurize again and got a clue ...

Traceback (most recent call last):
... (snipped)
File
"c:\users\miked\env\xxdx\lib\site-packages\libfuturize\fixer_util.py",
line 374, in check_future_import
assert 0, "strange import: %s" % savenode
AssertionError: strange import: from __future__ import
(unicode_literals, division)


Whereupon I searched for the offending text and removed the parentheses
from the import line and all was well.

Lovely software - thanks Ed

Mike
Brett Cannon
2014-03-12 15:17:06 UTC
Permalink
I hope Ed is on this mailing list, but in case he isn't you might want to
file an official bug at https://github.com/PythonCharmers/python-future .
Post by Mike Dewhirst
While porting a project - all modules at once - futurize threw a
traceback without contextual clues for which of my modules it found
problematic.
... (snipped)
File
"c:\users\miked\env\xxdx\lib\site-packages\libfuturize\fixer_util.py",
line 373, in check_future_import
assert 0, "strange import"
AssertionError: strange import
Rather than start again one module at a time I rummaged around line 373
in fixer_util.py to see what it was trying to do.
---
C:/users/miked/env/xxdx/Lib/site-packages/libfuturize/fixer_util.py~
Sat
Feb 15 09:33:01 2014
+++ C:/users/miked/env/xxdx/Lib/site-packages/libfuturize/fixer_util.py
Sat Feb 15 09:33:17 2014
"""If this is a future import, return set of symbols that are
imported,
else return None."""
# node should be the import statement here
+ savenode = node
return set()
node = node.children[0]
return set([node.value])
- assert 0, "strange import"
+ assert 0, "strange import: %s" % savenode
Then I ran futurize again and got a clue ...
... (snipped)
File
"c:\users\miked\env\xxdx\lib\site-packages\libfuturize\fixer_util.py",
line 374, in check_future_import
assert 0, "strange import: %s" % savenode
AssertionError: strange import: from __future__ import
(unicode_literals, division)
Whereupon I searched for the offending text and removed the parentheses
from the import line and all was well.
Lovely software - thanks Ed
Mike
_______________________________________________
Python-porting mailing list
https://mail.python.org/mailman/listinfo/python-porting
Loading...