Skip to main content

Class Namespaces

Project description

https://travis-ci.org/mwchase/class-namespaces.svg?branch=master

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.0.tar.gz (6.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.4.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for class_namespaces-0.4.0.tar.gz
Algorithm Hash digest
SHA256 799fb497beea03924e72bf7b1f08c5f3fb8b450b9d470960584e82579d3884c4
MD5 bd46caf5a671e13d93d97087ad77a63f
BLAKE2b-256 7b59dc153cd79408112a3068d3352cb2ab28b336b446e3fc793b28fad058d505

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for class_namespaces-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf2bc84e0309233d0f549d67a1d699a3d99c53622a8d7307482dd3678d3a3dad
MD5 54caf7fb3cf853607ff71f12a4e84cf4
BLAKE2b-256 c3b10490335449e6703a808a5b86782bbe4bad9d297235ad5223232c05b0afc7

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