Class Namespaces
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for class_namespaces-0.6.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f950a77a7dddef351ab50e57a9fc4d3272c662dce659b091aa7098e68f6b599 |
|
MD5 | 82081deb72f75ed53979d07e64e4605c |
|
BLAKE2b-256 | 597d9d892d6903ffa89ba7e10f500b3b4834c29ce0446546680f250164e659d8 |