-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fail to analyze list comprehension code #412
Comments
How @app.route('/test')
def test_api():
response = {}
key_name = 'data'
response['Items'] = [
{'Timestamp' : 10, 'payload' : { 'data' : 1}},
{'Timestamp' : 11, 'payload' : { 'data' : 2}}
]
stamp = [item['Timestamp'] for item in response['Items']]
temps = [item['payload'][key_name] for item in response['Items']]
hums = [item['payload'][key_name] for item in response['Items']]
return {
'stamp': stamp,
'temps': temps,
} Result: |
@Segflow thanks for your comment. I could execute my code in local option, however, I cannot run 'deploy' or 'gen-policy'. |
I guess this issue is related to below codes. def _get_matching_sub_namespace(self, name):
# type: (str) -> symtable.SymbolTable
namespaces = [
t for t in self._symbol_table.get_sub_namespaces()
if t.get_name() == name]
if not namespaces:
return
# We're making a simplification and using the genexpr subnamespace.
# This has potential to miss a client call but we don't do
# inference on node.generators so this doesn't matter for now.
child_scope = namespaces[0]
return child_scope To handle list comprehension for temps = []
hums = []
for item in response['Items']:
temps.append(item['payload'][temp_key])
hums.append(item['payload'][hum_key]) |
The crash was caused by selecting the wrong child symbol table for the list comprehension. Previously we were always selecting the first one in the list of subtables. This is wrong if there is more than 1 list comprehension, since each one gets its own subtable. This is works fine if the list comprehension only uses symbols defined within itself or symbols that are shared between it and the first list comprehension in the enclosing scope, since that will resolve to the same value. The specific error case we are fixing is when there is a list comprehension that is not the first one that references a symbol from the enclosing function scope that the first list comprehension does not reference. Both the symbol tables and the ListComp node are annotated with a line number attribute, by matching these up we can select the correct subtable to go with our list comprehension. This is still naive, but is better than what we had before. fixes aws#412
Chalice does not deploy below code with error message 'key_name'.
If I change the code from item['payload'][key_name] to item['payload']['data'], it works well.
I have used version 1.0.0b1.
The text was updated successfully, but these errors were encountered: