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 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.

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.2.tar.gz (8.9 kB view hashes)

Uploaded Source

Built Distribution

class_namespaces-0.5.2-py3-none-any.whl (11.3 kB view hashes)

Uploaded Python 3

Supported by

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