2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-19 04:22:16 +00:00

Set __qualname__ for Python >= 3.3

This commit is contained in:
Jakob van Santen
2023-04-21 17:16:41 +02:00
committed by Stefan Seefeld
parent 8ca8724ad9
commit 58b1a010bb
2 changed files with 14 additions and 1 deletions

View File

@@ -502,6 +502,16 @@ namespace objects
);
}
str qualname(const char *name)
{
#if PY_VERSION_HEX >= 0x03030000
if (PyObject_HasAttrString(scope().ptr(), "__qualname__")) {
return str("%s.%s" % make_tuple(scope().attr("__qualname__"), name));
}
#endif
return str(name);
}
namespace
{
// Find a registered class object corresponding to id. Return a
@@ -564,6 +574,9 @@ namespace objects
object m = module_prefix();
if (m) d["__module__"] = m;
#if PY_VERSION_HEX >= 0x03030000
d["__qualname__"] = qualname(name);
#endif
if (doc != 0)
d["__doc__"] = doc;

View File

@@ -14,7 +14,7 @@
'X'
>>> X.Y
<class 'nested_ext.Y'>
<class 'nested_ext.X.Y'>
>>> X.Y.__module__
'nested_ext'