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

Analyzer throws exception when analyzing list comprehension as argument #263

Closed
gene1wood opened this issue Mar 28, 2017 · 1 comment
Closed
Labels

Comments

@gene1wood
Copy link
Contributor

The analyzer has difficulty with code like this

x = ''.join('a' for y in [1,2,3])

For example in an app like this

from chalice import Chalice, Response

app = Chalice(app_name='example')

@app.route('/')
def index():
    body = '<h1>test</h1>'
    x = ''.join('a' for y in [1,2,3])
    return Response(body=body,
                    status_code=200,
                    headers={'Content-Type': 'text/html'})

Expected Results

chalice gen-policy or chalice deploy should generate a policy or deploy the app

Actual Results

$ chalice gen-policy
Traceback (most recent call last):
  File "/usr/local/bin/chalice", line 11, in <module>
    load_entry_point('chalice==0.6.0', 'console_scripts', 'chalice')()
  File "/usr/local/lib/python2.7/dist-packages/chalice/cli/__init__.py", line 298, in main
    return cli(obj={})
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/chalice/cli/__init__.py", line 214, in gen_policy
    generated = policy.policy_from_source_code(contents)
  File "/usr/local/lib/python2.7/dist-packages/chalice/policy.py", line 20, in policy_from_source_code
    client_calls = get_client_calls_for_app(source_code)
  File "/usr/local/lib/python2.7/dist-packages/chalice/analyzer.py", line 74, in get_client_calls_for_app
    binder = t.bind_types()
  File "/usr/local/lib/python2.7/dist-packages/chalice/analyzer.py", line 331, in bind_types
    self.visit(self._current_ast_namespace)
  File "/usr/local/lib/python2.7/dist-packages/chalice/analyzer.py", line 540, in visit
    return ast.NodeVisitor.visit(self, node)
  File "/usr/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/usr/lib/python2.7/ast.py", line 249, in generic_visit
    self.visit(item)
  File "/usr/local/lib/python2.7/dist-packages/chalice/analyzer.py", line 540, in visit
    return ast.NodeVisitor.visit(self, node)
  File "/usr/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/usr/local/lib/python2.7/dist-packages/chalice/analyzer.py", line 390, in visit_Assign
    self.generic_visit(node)
  File "/usr/lib/python2.7/ast.py", line 251, in generic_visit
    self.visit(value)
  File "/usr/local/lib/python2.7/dist-packages/chalice/analyzer.py", line 540, in visit
    return ast.NodeVisitor.visit(self, node)
  File "/usr/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/usr/local/lib/python2.7/dist-packages/chalice/analyzer.py", line 424, in visit_Call
    self.generic_visit(node)
  File "/usr/lib/python2.7/ast.py", line 249, in generic_visit
    self.visit(item)
  File "/usr/local/lib/python2.7/dist-packages/chalice/analyzer.py", line 540, in visit
    return ast.NodeVisitor.visit(self, node)
  File "/usr/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/usr/lib/python2.7/ast.py", line 249, in generic_visit
    self.visit(item)
  File "/usr/local/lib/python2.7/dist-packages/chalice/analyzer.py", line 540, in visit
    return ast.NodeVisitor.visit(self, node)
  File "/usr/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/usr/lib/python2.7/ast.py", line 251, in generic_visit
    self.visit(value)
  File "/usr/local/lib/python2.7/dist-packages/chalice/analyzer.py", line 540, in visit
    return ast.NodeVisitor.visit(self, node)
  File "/usr/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/usr/local/lib/python2.7/dist-packages/chalice/analyzer.py", line 381, in visit_Name
    self._symbol_table.get_inferred_type(node.id)
  File "/usr/local/lib/python2.7/dist-packages/chalice/analyzer.py", line 241, in get_inferred_type
    symbol = self._local_table.lookup(name)
  File "/usr/lib/python2.7/symtable.py", line 100, in lookup
    flags = self._table.symbols[name]
KeyError: 'y'
@gene1wood gene1wood changed the title Analyzer throws exception when analyzing Analyzer throws exception when analyzing list comprehension as argument Mar 28, 2017
@jamesls
Copy link
Member

jamesls commented Apr 28, 2017

Confirmed bug, thanks for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants