[Python-porting] edge case

Mike Dewhirst miked at dewhirst.com.au
Sat Feb 15 00:18:47 CET 2014
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


More information about the Python-porting mailing list