tracer: fix get_var_name() to work on toplevel attributes.

E.g. this now works:

    >>> class dummy: pass
    >>> self = dummy()
    >>> self.foo = Signal()
    >>> self.foo.name
    'foo'
This commit is contained in:
whitequark 2020-05-04 05:51:08 +00:00
parent e301798cee
commit 393c27ac8e

View file

@ -37,7 +37,7 @@ def get_var_name(depth=2, default=_raise_exception):
elif opc == "STORE_DEREF":
name_index = int(code.co_code[index + 1])
return code.co_cellvars[name_index]
elif opc in ("LOAD_GLOBAL", "LOAD_ATTR", "LOAD_FAST", "LOAD_DEREF",
elif opc in ("LOAD_GLOBAL", "LOAD_NAME", "LOAD_ATTR", "LOAD_FAST", "LOAD_DEREF",
"DUP_TOP", "BUILD_LIST"):
index += 2
else: