candv: Constants & Values¶
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 thecontext
param.
1.4.0 (Oct 30, 2020)
API changes: public API is not changed, however, the following internal changes are introduced:
candv.base
is moved tocandv.core
.- Package-level definitions in
candv
are moved tocandv.ext
. candv.version
module is added.- Package-specific exceptions are defined in
candv.exceptions
. Work as before, but now exceptions can be caught more precisely if needed. candv.SimpleConstant
is a direct reference tocandv.core.SimpleConstant
now. Previously it was an alias tocandv.base.Constant
.candv.Constants
is a direct reference tocandv.core.Constants
now. Previously it was an alias tocandv.base.ConstantsContainer
.
Python support:
- Support of all Python versions below
3.7
is dropped.
Other:
- All external dependencies are removed.
- The license is switched from
LGPLv3
toMIT
. - 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).
- Comparison of constants is fixed: now it is based on constant’s
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)
- Core classes are significantly refactored.
constant_class
now usescandv.SimpleConstant
as the default value (instead ofNone
, see Customization for more info).- 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.
- Constant’s
container
attribute is public now. Groups of constants have it too (see Hierarchies). - 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 tohas_name
.get_by_name
method is removed in favor of__getitem__
method.get
method with support of default value is introduced.
- All objects (containers, groups and constants) have
name
andfull_name
attributes now. This may be useful if names of constants are used as key values (e.g. for Redis). - Also, all objects have good
repr
now. - Mixin factory
candv.with_constant_class()
is introduced. It may help to define containers in a more compact way. - 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. - Exception messages are more informative now.
- Tests are moved out the package.
- Introductory documentation is improved. Other docs are updated too.
1.1.2 (Jul 6, 2014)
values
anditervalues
attributes are added toConstants
.
1.1.1 (Jun 21, 2014)
- switch license from
GPLv2
toLGPLv3
.
- switch license from
1.1.0 (Jun 21, 2014)
Choices
container is moved to django-candv-choices library.- Docs are updated and typos are fixed.
- 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