qualname
Python module to emulate the __qualname__ attribute for classes and methods (Python 3.3+) in older Python versions. See PEP 3155 for details.
Installation
pip install qualname
Usage
Assume these definitions:
class C:
def f():
pass
class D:
def g():
pass
In Python 3.3+, classes have a __qualname__ property:
>>> C.__qualname__ 'C' >>> C.f.__qualname__ 'C.f' >>> C.D.__qualname__ 'C.D' >>> C.D.g.__qualname__ 'C.D.g'
Unfortunately, Python 2 and early Python 3 versions do not have an (obvious) equivalent. qualname to the rescue:
from qualname import qualname >>> qualname(C) 'C' >>> qualname(C.f) 'C.f' >>> qualname(C.D) 'C.D' >>> qualname(C.D.g) 'C.D.g'
Victory!
How does it work?
Glad you ask.
This module uses source code inspection to figure out how (nested) classes and functions are defined in order to determine the qualified names for them. That means parsing the source file, and traversing the AST (abstract syntax tree). This sounds very hacky, and it is, but the Python interpreter itself does not have the necessary information, so this justifies extreme measures.
Now that you know how it works, you’ll also understand that this module only works when the source file is available. Fortunately this is the case in most circumstances.
License
BSD.
Feedback? Issues?
Metadata
Release files for qualname 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| qualname-0.1.0.tar.gz | 3.1 kB | Without provenance | Details for qualname-0.1.0.tar.gz |
Release files / qualname-0.1.0.tar.gz
| Download URL | qualname-0.1.0.tar.gz |
|---|---|
| Size | 3.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
277cf6aa4b2ad36beed1153cfa7bf521b210d54fbecb3d8eea0c5679cecc9ed8
|
|
BLAKE2b-256 checksum How to use checksums |
d9558701163104e69773bb3c9371094372b1f9057fd5fbf33ca8d3236a63a9c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for qualname 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.