Commit 83e496f
Ben Caller
Make get_call_names more resilient
Code where we call a method of something which isn't a variable name
e.g.
```
yesterday = (date.today() - timedelta(days=1)).strftime("%Y-%m-%d")
```
was causing pyt to crash.
Previously the else branch would only handle ast.Attribute, and crash on
everything else.
```
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/pyt/pyt/__main__.py", line 141, in <module>
main()
File "/pyt/pyt/__main__.py", line 97, in main
path
File "/pyt/pyt/cfg/make_cfg.py", line 40, in make_cfg
module_definitions
File "/pyt/pyt/cfg/expr_visitor.py", line 60, in __init__
self.init_cfg(node)
File "/pyt/pyt/cfg/expr_visitor.py", line 67, in init_cfg
module_statements = self.visit(node)
File "/usr/lib/python3.6/ast.py", line 253, in visit
return visitor(node)
File "/pyt/pyt/cfg/stmt_visitor.py", line 58, in visit_Module
return self.stmt_star_handler(node.body)
File "/pyt/pyt/cfg/stmt_visitor.py", line 79, in stmt_star_handler
node = self.visit(stmt)
File "/usr/lib/python3.6/ast.py", line 253, in visit
return visitor(node)
File "/pyt/pyt/cfg/stmt_visitor.py", line 413, in visit_Assign
return self.assignment_call_node(label.result, node)
File "/pyt/pyt/cfg/stmt_visitor.py", line 437, in assignment_call_node
call = self.visit(ast_node.value)
File "/usr/lib/python3.6/ast.py", line 253, in visit
return visitor(node)
File "/pyt/pyt/cfg/expr_visitor.py", line 540, in visit_Call
_id = get_call_names_as_string(node.func)
File "/pyt/pyt/core/ast_helper.py", line 78, in get_call_names_as_string
return _list_to_dotted_string(get_call_names(node))
File "/pyt/pyt/core/ast_helper.py", line 68, in get_call_names
return reversed(_get_call_names_helper(node, result))
File "/pyt/pyt/core/ast_helper.py", line 62, in _get_call_names_helper
return _get_call_names_helper(node.value, result)
File "/pyt/pyt/core/ast_helper.py", line 61, in _get_call_names_helper
result.append(node.attr)
AttributeError: 'BinOp' object has no attribute 'attr'
```1 parent e692581 commit 83e496f
2 files changed
Lines changed: 24 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 51 | + | |
55 | 52 | | |
56 | | - | |
| 53 | + | |
57 | 54 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
63 | 59 | | |
64 | 60 | | |
65 | 61 | | |
66 | 62 | | |
67 | | - | |
68 | | - | |
| 63 | + | |
69 | 64 | | |
70 | 65 | | |
71 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
733 | 733 | | |
734 | 734 | | |
735 | 735 | | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
0 commit comments