46 """Get a qualified name for the code running in `frame`.""" |
46 """Get a qualified name for the code running in `frame`.""" |
47 co = frame.f_code |
47 co = frame.f_code |
48 fname = co.co_name |
48 fname = co.co_name |
49 method = None |
49 method = None |
50 if co.co_argcount and co.co_varnames[0] == "self": |
50 if co.co_argcount and co.co_varnames[0] == "self": |
51 self = frame.f_locals["self"] |
51 self = frame.f_locals.get("self", None) |
52 method = getattr(self, fname, None) |
52 method = getattr(self, fname, None) |
53 |
53 |
54 if method is None: |
54 if method is None: |
55 func = frame.f_globals.get(fname) |
55 func = frame.f_globals.get(fname) |
56 if func is None: |
56 if func is None: |
57 return None |
57 return None |
58 return func.__module__ + '.' + fname |
58 return func.__module__ + "." + fname |
59 |
59 |
60 func = getattr(method, '__func__', None) |
60 func = getattr(method, "__func__", None) |
61 if func is None: |
61 if func is None: |
62 cls = self.__class__ |
62 cls = self.__class__ |
63 return cls.__module__ + '.' + cls.__name__ + "." + fname |
63 return cls.__module__ + "." + cls.__name__ + "." + fname |
64 |
64 |
65 if hasattr(func, '__qualname__'): |
65 return func.__module__ + "." + func.__qualname__ |
66 qname = func.__module__ + '.' + func.__qualname__ |
|
67 else: |
|
68 for cls in getattr(self.__class__, '__mro__', ()): |
|
69 f = cls.__dict__.get(fname, None) |
|
70 if f is None: |
|
71 continue |
|
72 if f is func: |
|
73 qname = cls.__module__ + '.' + cls.__name__ + "." + fname |
|
74 break |
|
75 else: |
|
76 # Support for old-style classes. |
|
77 def mro(bases): |
|
78 for base in bases: |
|
79 f = base.__dict__.get(fname, None) |
|
80 if f is func: |
|
81 return base.__module__ + '.' + base.__name__ + "." + fname |
|
82 for base in bases: |
|
83 qname = mro(base.__bases__) |
|
84 if qname is not None: |
|
85 return qname |
|
86 return None |
|
87 qname = mro([self.__class__]) |
|
88 if qname is None: |
|
89 qname = func.__module__ + '.' + fname |
|
90 |
|
91 return qname |
|