tracer: add Python 3.11 support.
This commit is contained in:
parent
8b85afa72e
commit
851546bf2d
|
@ -16,13 +16,15 @@ def get_var_name(depth=2, default=_raise_exception):
|
||||||
frame = sys._getframe(depth)
|
frame = sys._getframe(depth)
|
||||||
code = frame.f_code
|
code = frame.f_code
|
||||||
call_index = frame.f_lasti
|
call_index = frame.f_lasti
|
||||||
|
while call_index > 0 and opname[code.co_code[call_index]] == "CACHE":
|
||||||
|
call_index -= 2
|
||||||
while True:
|
while True:
|
||||||
call_opc = opname[code.co_code[call_index]]
|
call_opc = opname[code.co_code[call_index]]
|
||||||
if call_opc in ("EXTENDED_ARG",):
|
if call_opc in ("EXTENDED_ARG",):
|
||||||
call_index += 2
|
call_index += 2
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
if call_opc not in ("CALL_FUNCTION", "CALL_FUNCTION_KW", "CALL_FUNCTION_EX", "CALL_METHOD"):
|
if call_opc not in ("CALL_FUNCTION", "CALL_FUNCTION_KW", "CALL_FUNCTION_EX", "CALL_METHOD", "CALL"):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
index = call_index + 2
|
index = call_index + 2
|
||||||
|
@ -36,9 +38,11 @@ def get_var_name(depth=2, default=_raise_exception):
|
||||||
return code.co_varnames[name_index]
|
return code.co_varnames[name_index]
|
||||||
elif opc == "STORE_DEREF":
|
elif opc == "STORE_DEREF":
|
||||||
name_index = int(code.co_code[index + 1])
|
name_index = int(code.co_code[index + 1])
|
||||||
|
if sys.version_info >= (3, 11):
|
||||||
|
name_index -= code.co_nlocals
|
||||||
return code.co_cellvars[name_index]
|
return code.co_cellvars[name_index]
|
||||||
elif opc in ("LOAD_GLOBAL", "LOAD_NAME", "LOAD_ATTR", "LOAD_FAST", "LOAD_DEREF",
|
elif opc in ("LOAD_GLOBAL", "LOAD_NAME", "LOAD_ATTR", "LOAD_FAST", "LOAD_DEREF",
|
||||||
"DUP_TOP", "BUILD_LIST"):
|
"DUP_TOP", "BUILD_LIST", "CACHE", "COPY"):
|
||||||
index += 2
|
index += 2
|
||||||
else:
|
else:
|
||||||
if default is _raise_exception:
|
if default is _raise_exception:
|
||||||
|
|
Loading…
Reference in a new issue