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://codecov.io/gh/mwchase/class-namespaces/branch/master/graph/badge.svg Code Health Scrutinizer Code Quality Code Coverage Build Status Code Climate Test Coverage 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(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.

  • Some pytest constructs behave weirdly inside the class definitions. Hopefully, this doesn’t matter to anyone not writing tests for the package.

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.5.6.tar.gz (12.0 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.5.6-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for class_namespaces-0.5.6.tar.gz
Algorithm Hash digest
SHA256 924d81a8e2861182bc5a47f18cfd627713433ffac8f29b117b58f0219ab72834
MD5 addb3d68f05dca183de1d4a3708851c5
BLAKE2b-256 14d76c576fc1eac9c3be58d1a3a7348b064c7f4f3dd311dcdca0fa8bcd1ea3a6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for class_namespaces-0.5.6-py3-none-any.whl
Algorithm Hash digest
SHA256 eb85ec0b3b1c9c6c49df63c6670ed337bb63115f3d06673895ca56ea06ec0bbb
MD5 dab3e2d61f9d5866129ef43b4734392d
BLAKE2b-256 029470e6f4b1f1daee06c4065050f590606e44f7616c65a31481814134cd0b55

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