Skip to content

fails on from x import y #1

Description

@jonathaneunice
$ python
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import ast
>>> import codegen
>>> a = ast.parse('import stuf')
>>> print ast.dump(a)
Module(body=[Import(names=[alias(name='stuf', asname=None)])])
>>> print codegen.to_source(a)
import stuf
>>> # so far, so good!
... 

>>> b = ast.parse('from stuf import orderedstuf')
>>> print ast.dump(b)
Module(body=[ImportFrom(module='stuf', names=[alias(name='orderedstuf', asname=None)], level=0)])
>>> print codegen.to_source(b)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/codegen.py", line 70, in to_source
    return ''.join(generator.result)
TypeError: sequence item 2: expected string, alias found
>>> # uh... something broke
... 
>>> 

In looking this over, codegen is based on a 2008 code release. I have not explored them yet, but have found several other forks / descendants of the same code: this refactoring and then an evolved derivative of that: astor. At least one, astor successfully handles this from x import y construction.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions