Given a python ast that represents a function call, clear and create our generic Call object. Some calls have no chance at resolution (e.g. array[2](param)) so we return nothing instead. :param func ast: :rtype: Call|None
(func)
| 7 | |
| 8 | |
| 9 | def get_call_from_func_element(func): |
| 10 | """ |
| 11 | Given a python ast that represents a function call, clear and create our |
| 12 | generic Call object. Some calls have no chance at resolution (e.g. array[2](param)) |
| 13 | so we return nothing instead. |
| 14 | |
| 15 | :param func ast: |
| 16 | :rtype: Call|None |
| 17 | """ |
| 18 | assert type(func) in (ast.Attribute, ast.Name, ast.Subscript, ast.Call) |
| 19 | if type(func) == ast.Attribute: |
| 20 | owner_token = [] |
| 21 | val = func.value |
| 22 | while True: |
| 23 | try: |
| 24 | owner_token.append(getattr(val, 'attr', val.id)) |
| 25 | except AttributeError: |
| 26 | pass |
| 27 | val = getattr(val, 'value', None) |
| 28 | if not val: |
| 29 | break |
| 30 | if owner_token: |
| 31 | owner_token = djoin(*reversed(owner_token)) |
| 32 | else: |
| 33 | owner_token = OWNER_CONST.UNKNOWN_VAR |
| 34 | return Call(token=func.attr, line_number=func.lineno, owner_token=owner_token) |
| 35 | if type(func) == ast.Name: |
| 36 | return Call(token=func.id, line_number=func.lineno) |
| 37 | if type(func) in (ast.Subscript, ast.Call): |
| 38 | return None |
| 39 | |
| 40 | |
| 41 | def make_calls(lines): |
no test coverage detected