Skip to main content
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.

  • abstractmethods. See the compat module.

Things that don’t work:

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

  • No way to have instance Namespaces on non-hashable types, or subclasses of some built-in types, particularly tuple. Try using data descriptors instead.

Things that might work:

  • New namespace features in Python 3.6. Current testing is spotty.

  • Combining with other metaclasses. Unfortunately, the current setup is somewhat brittle. It may be necessary to experiment with the ordering of bases.

Release files for class-namespaces 0.6.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for class-namespaces 0.6.3
File Size Uploaded
class_namespaces-0.6.3.tar.gz 15.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for class-namespaces 0.6.3
File Interpreter ABI Platform
class_namespaces-0.6.3-py3-none-any.whl Python 3 none any Details

Total release size: 31.2 kB

Release files / class_namespaces-0.6.3.tar.gz

Download URL class_namespaces-0.6.3.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
de91ac2d9395d244fe866b5445e0fa210ba75d174680d8ede29e6b796ec78436
BLAKE2b-256 checksum
How to use checksums
4f8b548d57ae90cf93290d0e331c3bb252cd7365c071bfb436549b85ba699cb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / class_namespaces-0.6.3-py3-none-any.whl

Download URL class_namespaces-0.6.3-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d1e98b5a51df544fedc46bbe91f383c619a6e2edf0a83c4296f2f68a57870dc7
BLAKE2b-256 checksum
How to use checksums
ed20b7889fe681e1f21288cb241db8a4d3c068258221b3806dd5d9cc2dcfc8e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.6.3 This release

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page