5

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?

2 Answers2

2

You can use executing:

executing.Source.for_frame(frame).code_qualname(frame.f_code)
Alex Hall
  • 34,833
  • 5
  • 57
  • 89
1

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.

ecatmur
  • 152,476
  • 27
  • 293
  • 366
  • Thanks. Python inspection is a patchwork and more clumsy than useful IMHO. But perhaps the underlying architecture is the clumsy patchwork? – carpetemporem Aug 31 '12 at 16:02
  • @carpetemporem Part of the problem is that inspection has to work on top of multiple implementations which differ quite severely: CPython, Jython, IronPython, PyPy and even Stackless. – ecatmur Aug 31 '12 at 16:08
  • Yep, legacy code. But IMHO Python 3 could have been a chance for a fundamental redesign of a language which was simple and not bad for a starter but becomes more and more of a mess. Chance lost. – carpetemporem Sep 01 '12 at 13:44