PythonCharmers / python-future

Easy, clean, reliable Python 2/3 compatibility
http://python-future.org
MIT License
1.17k stars 291 forks source link

Tracback with fix_future_standard_library_urllib #45

Closed wluebbe closed 10 years ago

wluebbe commented 10 years ago

Running futurize --verbose -f libfuturize.fixes.fix_future_standard_library_urllib on the file from __future__ import print_function from urllib import urlopen, urlencode oeis_url = 'http://oeis.org/' def _fetch(url): try: f = urlopen(url) result = f.read() f.close() return result except IOError as msg: raise IOError("%s\nError fetching %s." % (msg, url)) gives the traceback RefactoringTool: Refactoring src/sage/databases/oeis-2.py Traceback (most recent call last): File "/usr/local/bin/futurize", line 9, in <module> load_entry_point('future==0.12.0-dev', 'console_scripts', 'futurize')() File "/usr/local/lib/python2.7/dist-packages/future-0.12.0_dev-py2.7.egg/libfuturize/main.py", line 276, in main options.processes) File "/usr/lib/python2.7/lib2to3/refactor.py", line 706, in refactor items, write, doctests_only) File "/usr/lib/python2.7/lib2to3/refactor.py", line 301, in refactor self.refactor_file(dir_or_file, write, doctests_only) File "/usr/lib/python2.7/lib2to3/refactor.py", line 747, in refactor_file *args, **kwargs) File "/usr/lib/python2.7/lib2to3/refactor.py", line 354, in refactor_file tree = self.refactor_string(input, filename) File "/usr/lib/python2.7/lib2to3/refactor.py", line 386, in refactor_string self.refactor_tree(tree, name) File "/usr/lib/python2.7/lib2to3/refactor.py", line 460, in refactor_tree new = fixer.transform(node, results) File "/usr/local/lib/python2.7/dist-packages/future-0.12.0_dev-py2.7.egg/libfuturize/fixes/fix_future_standard_library_urllib.py", line 24, in transform touch_import_top(u'future', u'standard_library', node) File "/usr/local/lib/python2.7/dist-packages/future-0.12.0_dev-py2.7.egg/libfuturize/fixer_util.py", line 303, in touch_import_top root = find_root(node) File "/usr/lib/python2.7/lib2to3/fixer_util.py", line 279, in find_root raise ValueError("root found before file_input node was found.") ValueError: root found before file_input node was found. But with the file from __future__ import print_function import urllib oeis_url = 'http://oeis.org/' def _fetch(url): try: f = urllib.urlopen(url) result = f.read() f.close() return result except IOError as msg: raise IOError("%s\nError fetching %s." % (msg, url)) it is OK. But I understand too little about the 2to3 tool to find the cause :-( Of course I can change the module before running futurize - but perhaps it is easy to fix.

edschofield commented 10 years ago

Thanks for the bug report!

This only affected the develop branch. It should be fixed now on that branch.

wluebbe commented 10 years ago

Yes, it is fixed. Thank you!