candv: Constants & Values

Version of PyPI package Supported versions of Python Documentation Status MIT license

Build status of the master branch on Linux Build status of the master branch on Windows Code quality provided by «Codebeat» Code quality provided by «Codacy» Code quality provided by «Scrutinizer CI»

candv allows to create complex enum-like constants.

In contrast to other methods of defining constants, candv helps to organize and to document classes of constants.

This is done by providing iteration and lookup facilities for containers of constants.

Additionally, candv provides an ability to attach human-readable names, descriptions, arbitrary values, and methods to constants.

Inspired by Constants from Twisted and Form Fields from Django.

Changelog

  • 1.5.0 (Nov 18, 2020)

    API changes:

    • to_primitive() methods use *args and **kwargs instead of the context param.
  • 1.4.0 (Oct 30, 2020)

    API changes: public API is not changed, however, the following internal changes are introduced:

    1. candv.base is moved to candv.core.
    2. Package-level definitions in candv are moved to candv.ext.
    3. candv.version module is added.
    4. Package-specific exceptions are defined in candv.exceptions. Work as before, but now exceptions can be caught more precisely if needed.
    5. candv.SimpleConstant is a direct reference to candv.core.SimpleConstant now. Previously it was an alias to candv.base.Constant.
    6. candv.Constants is a direct reference to candv.core.Constants now. Previously it was an alias to candv.base.ConstantsContainer.

    Python support:

    • Support of all Python versions below 3.7 is dropped.

    Other:

    1. All external dependencies are removed.
    2. The license is switched from LGPLv3 to MIT.
    3. The documentation is reworked to be more explanatory and concise.
  • 1.3.1 (Aug 1, 2015)

    • Comparison of constants is fixed: now it is based on constant’s full_name attribute (issue #11).
  • 1.3.0 (Dec 31, 2014)

    • to_primitive() method is implemented. This can be used for serialization, for example, into JSON (issue #1). See usage and customization for more info.
  • 1.2.0 (Oct 11, 2014)

    1. Core classes are significantly refactored.
    2. constant_class now uses candv.SimpleConstant as the default value (instead of None, see Customization for more info).
    3. Support of groups is reimplemented: now they are classes just as other constants containers (previously groups were instances of patched containers). So, groups automatically gain all of those attributes and methods which usual containers have.
    4. Constant’s container attribute is public now. Groups of constants have it too (see Hierarchies).
    5. API of containers is made really close to API of Python’s dict (see usage for more info):
      • __getitem__, __contains__, __len__ and __iter__ magic methods are implemented.
      • contains method is renamed to has_name.
      • get_by_name method is removed in favor of __getitem__ method.
      • get method with support of default value is introduced.
    6. All objects (containers, groups and constants) have name and full_name attributes now. This may be useful if names of constants are used as key values (e.g. for Redis).
    7. Also, all objects have good repr now.
    8. Mixin factory candv.with_constant_class() is introduced. It may help to define containers in a more compact way.
    9. A potential bug of uninitialized unbounded constants is fixed. Unbounded constant is an instance of a class which differs from container’s constant_class or its subclasses. This is unnatural case, but if this is really needed, it will not break now.
    10. Exception messages are more informative now.
    11. Tests are moved out the package.
    12. Introductory documentation is improved. Other docs are updated too.
  • 1.1.2 (Jul 6, 2014)

    • values and itervalues attributes are added to Constants.
  • 1.1.1 (Jun 21, 2014)

    • switch license from GPLv2 to LGPLv3.
  • 1.1.0 (Jun 21, 2014)

    1. Choices container is moved to django-candv-choices library.
    2. Docs are updated and typos are fixed.
    3. Utils are stripped from requirements.
  • 1.0.0 (Apr 15, 2014)

    • Initial version.

Sources

Feel free to explore, fork or contribute: https://github.com/oblalex/candv

Indices and tables