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.6.0.tar.gz (15.7 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.6.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for class_namespaces-0.6.0.tar.gz
Algorithm Hash digest
SHA256 16b0d68fdb184a925e22505e7f0a9288875592f3cb3b8ca9e93ed50a1c51c047
MD5 c781614610276599279aaa7cfd9cb128
BLAKE2b-256 d0a13d57bb02ebd0befa9724f49e272e324b9a05beb0701791c12dfc7dfc74ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for class_namespaces-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f950a77a7dddef351ab50e57a9fc4d3272c662dce659b091aa7098e68f6b599
MD5 82081deb72f75ed53979d07e64e4605c
BLAKE2b-256 597d9d892d6903ffa89ba7e10f500b3b4834c29ce0446546680f250164e659d8

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