Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

__qualname__ emulation for older Python versions

Project description

Python module to emulate the __qualname__ attribute for classes and methods (Python 3.3+) in older Python versions. See PEP 3155 for details. Downloads Latest Version Supported Python versions Development Status License


pip install qualname


Assume these definitions:

class C:
    def f():

    class D:
        def g():

In Python 3.3+, classes have a __qualname__ property:

>>> C.__qualname__
>>> C.f.__qualname__
>>> C.D.__qualname__
>>> C.D.g.__qualname__

Unfortunately, Python 2 and early Python 3 versions do not have an (obvious) equivalent. qualname to the rescue:

from qualname import qualname

>>> qualname(C)
>>> qualname(C.f)
>>> qualname(C.D)
>>> qualname(C.D.g)


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.



Release history Release notifications

This version
History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
qualname-0.1.0.tar.gz (3.1 kB) Copy SHA256 hash SHA256 Source None Apr 11, 2015

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page