Skip to content

Version 0.2.0

Pre-release
Pre-release
Compare
Choose a tag to compare
@ForeverWintr ForeverWintr released this 15 Aug 05:14
· 17 commits to master since this release
0403743

This adds the namespace decorator, intended for use on class_only classes that just define constant attributes.

For example, given the following class:

from class_only_design import namespace

@namespace
class ColourConstants:
    RED = 'FF0000'
    GREEN = '00FF00'
    BLUE = '0000FF'

The namespace decorator provides the mutability and instanciation protections of class_only, but also:

  • makes the class iterable, e.g.:

    list(ColourConstants) # returns ['FF0000', '00FF00', '0000FF']
  • adds a special attribute, nameof which returns the name of the class attribute:

    ColourConstants.nameof.RED # returns 'RED'

It also improves the underlying implementation of the class decorators. They no longer modify the class hierarchy.