MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / get_clsname_for_code

Function get_clsname_for_code

_pydevd_bundle/pydevd_utils.py:110–136  ·  view source on GitHub ↗
(code, frame)

Source from the content-addressed store, hash-verified

108
109
110def get_clsname_for_code(code, frame):
111 clsname = None
112 if len(code.co_varnames) > 0:
113 # We are checking the first argument of the function
114 # (`self` or `cls` for methods).
115 first_arg_name = code.co_varnames[0]
116 if first_arg_name in frame.f_locals:
117 first_arg_obj = frame.f_locals[first_arg_name]
118 if inspect.isclass(first_arg_obj): # class method
119 first_arg_class = first_arg_obj
120 else: # instance method
121 if hasattr(first_arg_obj, "__class__"):
122 first_arg_class = first_arg_obj.__class__
123 else: # old style class, fall back on type
124 first_arg_class = type(first_arg_obj)
125 func_name = code.co_name
126 if hasattr(first_arg_class, func_name):
127 method = getattr(first_arg_class, func_name)
128 func_code = None
129 if hasattr(method, "func_code"): # Python2
130 func_code = method.func_code
131 elif hasattr(method, "__code__"): # Python3
132 func_code = method.__code__
133 if func_code and func_code == code:
134 clsname = first_arg_class.__name__
135
136 return clsname
137
138
139def get_non_pydevd_threads():

Callers 3

get_func_nameFunction · 0.90
get_func_nameMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected