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

Support for Python 3.6 Constant nodes #120

Closed
chrisrink10 opened this issue Sep 30, 2018 · 1 comment
Closed

Support for Python 3.6 Constant nodes #120

chrisrink10 opened this issue Sep 30, 2018 · 1 comment

Comments

@chrisrink10
Copy link
Contributor

In Python 3.6, the new ast.Constant node was introduced, ostensibly for the purposes of constant folding. However, in Python 3.8, it appears that it is being used to replace ast.Str, ast.Bytes, ast.Num, ast.Ellipsis, and ast.NameConstant.

Since astor doesn't include a visit_Constant method on its SourceGenerator, attempting to emit code generated with ast.Constant causes a lot of errors.

  • CPython 3.6 issue adding ast.Constant
  • CPython 3.8 issue and commit switching to using ast.Constant
@jmfrank63
Copy link

I just ran into this problem. Here is the error message on Travis CI (only fails for python 3.8-dev) just in case this might be helpful:

    def test_get_module_trees_by_dir(mod_path, source, non_pub_source):
        modules = get_module_trees_by_dir(mod_path)
        assert len(modules) == 2
>       sources = [astor.to_source(mod) for mod in modules]
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/trio/tests/tools/test_gen_exports.py:130: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/trio/tests/tools/test_gen_exports.py:130: in <listcomp>
    sources = [astor.to_source(mod) for mod in modules]
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/astor/code_gen.py:52: in to_source
    generator.visit(node)
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/astor/code_gen.py:802: in visit_Module
    self.write(*node.body)
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/astor/code_gen.py:168: in write
    visit(item)
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/astor/code_gen.py:320: in visit_FunctionDef
    self.body(node.body)
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/astor/code_gen.py:218: in body
    self.write(*statements)
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/astor/code_gen.py:168: in write
    visit(item)
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/astor/code_gen.py:310: in visit_Expr
    self.generic_visit(node)
/opt/python/3.8-dev/lib/python3.8/ast.py:352: in generic_visit
    self.visit(value)
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
node = <_ast.Constant object at 0x7fcd26a5efd0>
    def abort_visit(node):  # XXX: self?
        msg = 'No defined handler for node of type %s'
>       raise AttributeError(msg % node.__class__.__name__)
E       AttributeError: No defined handler for node of type Constant
../../../../virtualenv/python3.8-dev/lib/python3.8/site-packages/astor/node_util.py:137: AttributeError

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