tracer: fix get_var_name() to work on toplevel attributes.
authorwhitequark <whitequark@whitequark.org>
Mon, 4 May 2020 05:51:08 +0000 (05:51 +0000)
committerwhitequark <whitequark@whitequark.org>
Sun, 17 May 2020 19:51:58 +0000 (19:51 +0000)
E.g. this now works:

    >>> class dummy: pass
    >>> self = dummy()
    >>> self.foo = Signal()
    >>> self.foo.name
    'foo'

nmigen/tracer.py

index f02ecd336046938a723f1fef502e76ff370cffb7..17795f3b30a31ec71307d09adf62615b34832f78 100644 (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: