Skip to main content

Class Namespaces

Project description

Documentation Status https://travis-ci.org/mwchase/class-namespaces.svg?branch=master https://coveralls.io/repos/github/mwchase/class-namespaces/badge.svg?branch=master https://api.codacy.com/project/badge/Grade/f73ed5e3849c4049b8c9e3f17f6589da https://ci.appveyor.com/api/projects/status/ik5ci1icjmib9fi7?svg=true https://codecov.io/gh/mwchase/class-namespaces/branch/master/graph/badge.svg Code Health Scrutinizer Code Quality Build Status Code Climate Issue Count

Well-behaved class namespacing in Python. Inspired by https://erezsh.wordpress.com/2008/06/27/namespaces-lets-do-more-of-those-python-hackery/

Basic Usage

Example code:

import class_namespaces as cn

class MyCls(metaclass=cn.Namespaceable):

    var = 1

    with cn.Namespace() as my_ns:
        var = 2

assert MyCls.var == 1
assert MyCls.my_ns.var == 2

Other things that work:

  • Descriptors (methods, classmethods, staticmethods, properties, custom descriptors)

  • super()

  • Prepopulating Namespaces. The constructor takes the same arguments as a dict.

Things that don’t work:

  • Combining with nearly any other metaclass.

  • Various ways of putting a Namespace in a Namespace that I didn’t see an obvious way to handle. In particular…

    • There is no way to put an established namespace directly into another namespace.

Things that might work:

  • New namespace features in Python 3.6. Current testing is spotty.

Project details


Download files

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

Source Distribution

class_namespaces-0.4.1.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

class_namespaces-0.4.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file class_namespaces-0.4.1.tar.gz.

File metadata

File hashes

Hashes for class_namespaces-0.4.1.tar.gz
Algorithm Hash digest
SHA256 4916210b202532897f5be5fa518055a2ec09e37922ac9e121a934f05e9c49122
MD5 5c1332dfeb21fc9d7ecda265d0053644
BLAKE2b-256 be454b4508dee79849e807af66016939835d9d290e66ecfc119a9e922299999e

See more details on using hashes here.

File details

Details for the file class_namespaces-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for class_namespaces-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5fe8196f395022e6a9a98a48b1d0727eafa0936b79bf34ff15fda03e84dbb57f
MD5 040e1f0018aa6b4dece71e217f1e2fb2
BLAKE2b-256 51fe0cf302abbfce26c33c855935890fe8d137373975bad8c1ceb453f4c78814

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page