qualname


Namequalname JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/wbolster/qualname
Summary__qualname__ emulation for older Python versions
upload_time2015-04-11 22:51:43
maintainerNone
docs_urlNone
authorWouter Bolsterlee
requires_pythonNone
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            ========
qualname
========

Python module to emulate the ``__qualname__`` attribute for classes and methods
(Python 3.3+) in older Python versions. See `PEP 3155`__ for details.

__ https://www.python.org/dev/peps/pep-3155/

.. image:: https://travis-ci.org/wbolster/qualname.svg?branch=master
   :target: https://travis-ci.org/wbolster/qualname

.. image:: https://pypip.in/download/qualname/badge.svg
   :target: https://pypi.python.org/pypi/qualname/
   :alt: Downloads

.. image:: https://pypip.in/version/qualname/badge.svg
   :target: https://pypi.python.org/pypi/qualname/
   :alt: Latest Version

.. image:: https://pypip.in/py_versions/qualname/badge.svg
   :target: https://pypi.python.org/pypi/qualname/
   :alt: Supported Python versions

.. image:: https://pypip.in/status/qualname/badge.svg
   :target: https://pypi.python.org/pypi/qualname/
   :alt: Development Status

.. image:: https://pypip.in/license/qualname/badge.svg
   :target: https://pypi.python.org/pypi/qualname/
   :alt: License

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?
=================

https://github.com/wbolster/qualname
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/wbolster/qualname",
    "name": "qualname",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Wouter Bolsterlee",
    "author_email": "uws@xs4all.nl",
    "download_url": "https://files.pythonhosted.org/packages/d9/55/8701163104e69773bb3c9371094372b1f9057fd5fbf33ca8d3236a63a9c1/qualname-0.1.0.tar.gz",
    "platform": "UNKNOWN",
    "description": "========\nqualname\n========\n\nPython module to emulate the ``__qualname__`` attribute for classes and methods\n(Python 3.3+) in older Python versions. See `PEP 3155`__ for details.\n\n__ https://www.python.org/dev/peps/pep-3155/\n\n.. image:: https://travis-ci.org/wbolster/qualname.svg?branch=master\n   :target: https://travis-ci.org/wbolster/qualname\n\n.. image:: https://pypip.in/download/qualname/badge.svg\n   :target: https://pypi.python.org/pypi/qualname/\n   :alt: Downloads\n\n.. image:: https://pypip.in/version/qualname/badge.svg\n   :target: https://pypi.python.org/pypi/qualname/\n   :alt: Latest Version\n\n.. image:: https://pypip.in/py_versions/qualname/badge.svg\n   :target: https://pypi.python.org/pypi/qualname/\n   :alt: Supported Python versions\n\n.. image:: https://pypip.in/status/qualname/badge.svg\n   :target: https://pypi.python.org/pypi/qualname/\n   :alt: Development Status\n\n.. image:: https://pypip.in/license/qualname/badge.svg\n   :target: https://pypi.python.org/pypi/qualname/\n   :alt: License\n\nInstallation\n============\n\n::\n\n  pip install qualname\n\n\nUsage\n=====\n\nAssume these definitions:\n\n::\n\n  class C:\n      def f():\n          pass\n\n      class D:\n          def g():\n              pass\n\nIn Python 3.3+, classes have a ``__qualname__`` property::\n\n  >>> C.__qualname__\n  'C'\n  >>> C.f.__qualname__\n  'C.f'\n  >>> C.D.__qualname__\n  'C.D'\n  >>> C.D.g.__qualname__\n  'C.D.g'\n\nUnfortunately, Python 2 and early Python 3 versions do not have an (obvious)\nequivalent. ``qualname`` to the rescue::\n\n  from qualname import qualname\n\n  >>> qualname(C)\n  'C'\n  >>> qualname(C.f)\n  'C.f'\n  >>> qualname(C.D)\n  'C.D'\n  >>> qualname(C.D.g)\n  'C.D.g'\n\nVictory!\n\n\nHow does it work?\n=================\n\nGlad you ask.\n\nThis module uses source code inspection to figure out how (nested) classes and\nfunctions are defined in order to determine the qualified names for them. That\nmeans parsing the source file, and traversing the AST (abstract syntax tree).\nThis sounds very hacky, and it is, but the Python interpreter itself does not\nhave the necessary information, so this justifies extreme measures.\n\nNow that you know how it works, you'll also understand that this module only\nworks when the source file is available. Fortunately this is the case in most\ncircumstances.\n\n\nLicense\n=======\n\nBSD.\n\n\nFeedback? Issues?\n=================\n\nhttps://github.com/wbolster/qualname",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "__qualname__ emulation for older Python versions",
    "version": "0.1.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d9558701163104e69773bb3c9371094372b1f9057fd5fbf33ca8d3236a63a9c1",
                "md5": "fdc9b7a3174000908fab184a295f9622",
                "sha256": "277cf6aa4b2ad36beed1153cfa7bf521b210d54fbecb3d8eea0c5679cecc9ed8"
            },
            "downloads": -1,
            "filename": "qualname-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "fdc9b7a3174000908fab184a295f9622",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3088,
            "upload_time": "2015-04-11T22:51:43",
            "upload_time_iso_8601": "2015-04-11T22:51:43.936914Z",
            "url": "https://files.pythonhosted.org/packages/d9/55/8701163104e69773bb3c9371094372b1f9057fd5fbf33ca8d3236a63a9c1/qualname-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2015-04-11 22:51:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "wbolster",
    "github_project": "qualname",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "qualname"
}
        
Elapsed time: 0.02484s