Closed njordr closed 3 years ago
Hi,
Hmm. Let's see if we can figure this out just by looking at the analyzer code. Since it's running the first branch of the if
, at least we know that node.value is not None
. Then, value = sanitize_exprs(node.value)
; that's a Pyan internal function, whose result should be a tuple.
It seems that for some reason, sanitize_exprs
is returning an empty tuple for this particular input.
To debug further, could you modify your copy of analyzer.py
, replacing the visit_AnnAssign
method with the version below (there's just one added print
), and then post the last thing it printed when it crashes?
def visit_AnnAssign(self, node): # PEP 526, Python 3.6+
target = sanitize_exprs(node.target)
self.last_value = None
if node.value is not None:
value = sanitize_exprs(node.value)
print(id(node), value, ast.dump(node.value)) # <--- added this print here
self.logger.debug("AnnAssign %s %s, %s:%s" % (get_ast_node_name(target[0]),
get_ast_node_name(value[0]),
self.filename, node.lineno))
self.analyze_binding(target, value)
else: # just a type declaration
self.logger.debug("AnnAssign %s <no value>, %s:%s" % (get_ast_node_name(target[0]),
self.filename, node.lineno))
self.last_value = None
self.visit(target[0])
# TODO: use the type annotation from node.annotation?
# http://greentreesnakes.readthedocs.io/en/latest/nodes.html#AnnAssign
These the values returned:
140309596494816
[]
List(elts=[], ctx=Load())
Thanks! Now I see the problem. node.value
is an empty list, so it obviously has no elements.
Since the code triggering the error is just a debug log call, I think it's safe to change the value[0]
to just value
. It'll sometimes produce a bit more stuff in the debug log, but that should be fine.
Could you try that and report back if it works? If so, I'll push a fix.
It works without the index, thanks
Thanks for testing! I'll push a fix.
Hi.
trying to run pyan against my code, it crashes with this error:
Cannot share my code, but if I could do something else to help you in debugging, just let me know