simonw/symbex

AttributeError: 'Call' object has no attribute 'value'

Closed this issue · 3 comments

Thanks to this issue:

I can now run symbex '*' -s in REALLY big directories, which is a great way to stress test it.

Got this:

# File: /Users/simon/Dropbox/Development/library-of-congress/.venv/lib/python3.6/site-packages/test/completion/pep0484_basic.py Line: 100
class SelfReference

Traceback (most recent call last):
  File "/Users/simon/.local/share/virtualenvs/symbex--e1aIHUb/bin/symbex", line 33, in <module>
    sys.exit(load_entry_point('symbex', 'console_scripts', 'symbex')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/simon/.local/share/virtualenvs/symbex--e1aIHUb/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/simon/.local/share/virtualenvs/symbex--e1aIHUb/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/simon/.local/share/virtualenvs/symbex--e1aIHUb/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/simon/.local/share/virtualenvs/symbex--e1aIHUb/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/simon/Dropbox/Development/symbex/symbex/cli.py", line 105, in cli
    snippet, line_no = code_for_node(code, node, class_name, signatures)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/simon/Dropbox/Development/symbex/symbex/lib.py", line 41, in code_for_node
    definition, lineno = function_definition(node), node.lineno
                         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/simon/Dropbox/Development/symbex/symbex/lib.py", line 150, in function_definition
    elif function_node.returns.value is None:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Call' object has no attribute 'value'

In the debugger:

python -i $(which symbex) '*' -s
(Pdb) function_node.__dict__
{'name': 'function_with_non_pep_0484_annotation',
'args': <ast.arguments object at 0x1034f97e0>,
'body': [<ast.Expr object at 0x1034f91e0>, <ast.Expr object at 0x1034f8e20>, <ast.Expr object at 0x1034fa830>, <ast.Expr object at 0x1034fadd0>, <ast.Expr object at 0x1034f8790>],
'decorator_list': [],
'returns': <ast.Call object at 0x1034f87f0>,
'type_comment': None,
'lineno': 115,
'col_offset': 0,
'end_lineno': 134,
'end_col_offset': 6}

I bounced up the stack a few times and found this:

def function_with_non_pep_0484_annotation(
        x: "I can put anything here",
        xx: "",
        yy: "\r\n\0;+*&^564835(---^&*34",
        y: 3 + 3,
        zz: float) -> int("42"):
    # infers int from function call
    #? int()
    x
    # infers int from function call
    #? int()
    xx
    # infers int from function call
    #? int()
    yy
    # infers str from function call
    #? str()
    y
    #? float()
    zz
#?

Looks like that's from the Jedi test suite: https://github.com/davidhalter/jedi/blob/3699ba0aa7efd1c18e366804a2fd82e242f54231/test/completion/pep0484_basic.py#L113

Since this is such an edge case I'm going to turn it into a -> ? in the output.

% symbex function_with_non_pep_0484_annotation -s -f tests/example_symbols.py 
# File: tests/example_symbols.py Line: 94
def function_with_non_pep_0484_annotation(x, xx, yy, y, zz: float) -> ?