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 qualnameVerified import paths — ran on the pinned version, not inferred.
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.
Ensure the object's source file is accessible. For built-in types, directly use `__name__` or `str(obj)`.
On Python 3.3+, simply access `obj.__qualname__` directly. No need to import or use the `qualname` library.
To get a fully qualified name, combine `obj.__module__` and `qualname(obj)` (or `obj.__qualname__` on Python 3.3+): `f'{obj.__module__}.{qualname(obj)}'`.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.
pip install qualname
Add `import qualname` at the beginning of your script to enable the `__qualname__` emulation for classes and functions defined thereafter.
Ensure that the argument passed to `qualname.qualname()` is a class, a function, or a method object.
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.
No dependency data recorded yet.