Reputation: 191
Python 3.3 introduced the __qualname__
attribute for function objects and class objects.
It's easy to get the (unqualified) name and a code object for the currently executing function.
But how to get the qualified name for the currently executing function?
Upvotes: 5
Views: 1218
Reputation: 2543
As of Python 3.11 this is now possible via:
inspect.currentframe().f_code.co_qualname
(with optional .f_back
s inserted before the .f_code
as desired)
https://docs.python.org/3.11/reference/datamodel.html#codeobject.co_qualname
Upvotes: 1
Reputation: 36043
You can use executing
:
executing.Source.for_frame(frame).code_qualname(frame.f_code)
Upvotes: 2
Reputation: 157484
I don't think you can, currently; see this thread.
Issue 13672 requests adding co_qualname
to code objects, and issue 12857 requests making the called function available through the frame object. Both have patches attached.
Upvotes: 1