8000 Fix issue #45: exception when replacing urllib usage · shawnp/python-future@0a8cfd7 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 0a8cfd7

Browse files
committed
Fix issue PythonCharmers#45: exception when replacing urllib usage
* The transform_member() function in lib2to3/fixes/fix_urllib.py breaks the * node object that is passed to it. This patch finds the root node * before calling that function so we can add the appropriate standard_library * import.
1 parent eeae7cd commit 0a8cfd7

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

libfuturize/fixer_util.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,14 @@ def touch_import_top(package, name_to_import, node):
292292
"""Works like `does_tree_import` but adds an import statement at the
293293
top if it was not imported (but below any __future__ imports).
294294
295-
Calling this multiple times adds them in reverse order.
295+
Based on lib2to3.fixer_util.touch_import()
296+
297+
Calling this multiple times adds the imports in reverse order.
296298
297299
Also adds "standard_library.install_hooks()" after "from future import
298-
standard_library". This should probably be factored into another function
299-
somehow.
300-
301-
Based on lib2to3.fixer_util.touch_import()
300+
standard_library". This should probably be factored into another function.
302301
"""
302+
303303
root = find_root(node)
304304

305305
if does_tree_import(package, name_to_import, root):

libfuturize/fixes/fix_future_standard_library_urllib.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,19 @@
1212
"""
1313

1414
from lib2to3.fixes.fix_urllib import FixUrllib
15-
from libfuturize.fixer_util import touch_import_top
15+
from libfuturize.fixer_util import touch_import_top, find_root
1616

1717

1818
class FixFutureStandardLibraryUrllib(FixUrllib): # not a subclass of FixImports
1919
run_order = 8
2020

2121
def transform(self, node, results):
22+
# transform_member() in lib2to3/fixes/fix_urllib.py breaks node so find_root(node)
23+
# no longer works after the super() call below. So we find the root first:
24+
root = find_root(node)
2225
result = super(FixFutureStandardLibraryUrllib, self).transform(node, results)
2326
# TODO: add a blank line between any __future__ imports and this?
24-
touch_import_top(u'future', u'standard_library', node)
27+
touch_import_top(u'future', u'standard_library', root)
2528
return result
2629

2730

0 commit comments

Comments
 (0)
0