Registry / serialization / qualname

qualname

JSON →
library0.1.0pypypi✓ verified 24d ago

The `qualname` Python module emulates the `__qualname__` attribute for classes and methods in older Python versions (specifically pre-Python 3.3). Introduced in PEP 3155, `__qualname__` provides a 'qualified name' including the full dotted path to an object within its module, which is particularly useful for nested definitions. This library achieves this by performing source code inspection and abstract syntax tree (AST) parsing, which means the source file must be available at runtime. The current version is 0.1.0, and its release cadence is infrequent, as its primary utility lies in supporting older Python environments.

pip install qualname
INSTALL
IMPORT
SIG · QUALNAME
Q
qualname
serializationpythonv0.1.0
Install
2.6s avg
Import
23ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.024s · 19.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.6s · import 0.022s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

qualname
from qualname import qualname

Demonstrates how to use the `qualname()` function to retrieve the qualified name for classes, methods, and nested functions. On Python 3.3+, native `__qualname__` is used, otherwise the library's emulation is applied.

import sys from qualname import qualname class Outer: def method_a(self): pass class Inner: def method_b(self): pass def top_level_func(): def nested_func(): pass return nested_func # For Python < 3.3, this library provides __qualname__ functionality # On Python 3.3+, objects already have __qualname__ print(f"Python Version: {sys.version.split(' ')[0]}") print(f"Outer.__qualname__: {qualname(Outer)}") print(f"Outer.method_a.__qualname__: {qualname(Outer.method_a)}") print(f"Outer.Inner.__qualname__: {qualname(Outer.Inner)}") print(f"Outer.Inner.method_b.__qualname__: {qualname(Outer.Inner.method_b)}") nested_f = top_level_func() print(f"top_level_func.__qualname__: {qualname(top_level_func)}") print(f"nested_f.__qualname__: {qualname(nested_f)}")
Debug
Known issues
gotchaThe library relies on source code inspection, meaning the source file must be available for `qualname()` to work. For objects like built-in types, or when the source cannot be determined (e.g., in some dynamically generated code), it may fall back to `__name__` or raise errors.
fix
Ensure the object's source file is accessible. For built-in types, directly use `__name__` or `str(obj)`.
affects: <0.1.0
gotchaThis library is primarily intended for Python versions older than 3.3. In Python 3.3 and later, the `__qualname__` attribute is a built-in feature of classes and functions, making this library redundant for those versions.
fix
On Python 3.3+, simply access `obj.__qualname__` directly. No need to import or use the `qualname` library.
affects: >=3.3
gotchaThe `__qualname__` attribute (whether native or emulated by this library) provides the dotted path within a module but does NOT include the module name itself. Users often expect a 'fully qualified name' that includes the module (e.g., `my_module.MyClass.my_method`).
fix
To get a fully qualified name, combine `obj.__module__` and `qualname(obj)` (or `obj.__qualname__` on Python 3.3+): `f'{obj.__module__}.{qualname(obj)}'`.
affects: *
gotchaFor inherited methods, `__qualname__` will report the qualified name from the class where the method was *defined*, not necessarily the class from which it is being accessed if the method is not overridden. This can lead to unexpected results if you expect `__qualname__` to always reflect the current class hierarchy.
fix
Be aware of inheritance behavior. If you need the `__qualname__` to reflect a child class for an inherited method, the method must be explicitly overridden in the child class.
affects: *
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'qualname'
The `qualname` package has not been installed in the current Python environment.
fix
pip install qualname
AttributeError: type object 'MyClass' has no attribute '__qualname__'
In Python versions prior to 3.3, the `__qualname__` attribute does not exist natively, and the `qualname` library was not imported to backport this functionality.
fix
Add `import qualname` at the beginning of your script to enable the `__qualname__` emulation for classes and functions defined thereafter.
TypeError: object is not a class, function, or method
The `qualname.qualname()` function is designed to retrieve the qualified name only for class objects, function objects, or method objects, and raises an error for other types (e.g., modules, variables, instances).
fix
Ensure that the argument passed to `qualname.qualname()` is a class, a function, or a method object.
TypeError: <built-in function/method name> is a built-in function/method
The `qualname` library relies on inspecting the source code, which is not available for built-in Python objects, leading to an error from the underlying `inspect.getsource` call.
fix
The `qualname` library cannot determine qualified names for built-in objects, as their source code is not accessible; this functionality is intended for user-defined Python objects.
Upgrade
Version history
0.1.0latest on PyPI · released Apr 11, 2015
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
qualname — pip install qualname · libregistry