Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple import form for __future__ imports confuses futurize #113

Closed
QuLogic opened this issue Oct 6, 2014 · 1 comment
Closed

Multiple import form for __future__ imports confuses futurize #113

QuLogic opened this issue Oct 6, 2014 · 1 comment

Comments

@QuLogic
Copy link
Contributor

QuLogic commented Oct 6, 2014

Running futurize -1 -a -w file.py on a file that contains from __future__ import (division, print_statement) (from some previous work, for example), fails with:

Traceback (most recent call last):
  File "/usr/bin/futurize", line 9, in <module>
    load_entry_point('future==0.14.1', 'console_scripts', 'futurize')()
  File "/usr/lib/python2.7/site-packages/libfuturize/main.py", line 295, in main
    options.processes)
  File "/usr/lib64/python2.7/lib2to3/refactor.py", line 706, in refactor
    items, write, doctests_only)
  File "/usr/lib64/python2.7/lib2to3/refactor.py", line 301, in refactor
    self.refactor_file(dir_or_file, write, doctests_only)
  File "/usr/lib64/python2.7/lib2to3/refactor.py", line 747, in refactor_file
    *args, **kwargs)
  File "/usr/lib64/python2.7/lib2to3/refactor.py", line 354, in refactor_file
    tree = self.refactor_string(input, filename)
  File "/usr/lib64/python2.7/lib2to3/refactor.py", line 386, in refactor_string
    self.refactor_tree(tree, name)
  File "/usr/lib64/python2.7/lib2to3/refactor.py", line 460, in refactor_tree
    new = fixer.transform(node, results)
  File "/usr/lib/python2.7/site-packages/libfuturize/fixes/fix_add__future__imports_except_unicode_literals.py", line 24, in transform
    future_import(u"print_function", node)
  File "/usr/lib/python2.7/site-packages/libfuturize/fixer_util.py", line 210, in future_import
    names = check_future_import(node)
  File "/usr/lib/python2.7/site-packages/libfuturize/fixer_util.py", line 424, in check_future_import
    assert False, "strange import: %s" % savenode
AssertionError: strange import: 
from __future__ import (division, print_function)

Note: Multiple imports on one line are usually against PEP8, but it seems that pep8 doesn't mind it with __future__ imports... Sorry, import x, y, z is against PEP8, but from a import x, y z is fine.

@Bernhard10
Copy link

In

from future.builtins.disabled import (apply, cmp, coerce, execfile,
                             file, long, raw_input, reduce, reload,
                             unicode, xrange, StandardError)

the StandardError also gets changed to

from future.builtins.disabled import (apply, cmp, coerce, execfile,
                             file, long, raw_input, reduce, reload,
                             unicode, xrange, Exception)

jmadler added a commit that referenced this issue Sep 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants