Advanced descriptors for special cases.
Project description
Advanced descriptors
This package includes helpers for special cases:
SeparateClassMethod - allow to have classmethod and normal method both with the same name.
AdvancedProperty - property with possibility to set class wide getter.
SeparateClassMethod
This descriptor can be set using standard decorator syntax. Create instance with arguments:
def imeth(instance):
return instance.value
def cmeth(owner):
return owner.value
class Target(object):
value = 1
def __init__(self):
self.value = 2
getval = advanced_descriptors.SeparateClassMethod(
imeth, cmeth
)
Create instance wrapping as decorator:
class Target(object):
value = 1
def __init__(self):
self.value = 2
@advanced_descriptors.SeparateClassMethod
def getval(self):
return self.value
@getval.class_method
def getval(cls):
return cls.value
Cases with method only and classmethod only is useless: method as-is and @classmethod should be used in corresponding cases.
AdvancedProperty
This descriptor should be used in cases, when in addition to normal property API, class getter is required. If class-wide setter and deleter also required - you should use standard propery in metaclass.
Usage examples:
In addition to normal property API:
class Target(object): _value = 777 def __init__(self): self._value = 42 @advanced_descriptors.AdvancedProperty def val(self): return self._value @val.setter def val(self, value): self._value = value @val.deleter def val(self): self._value = 0 @val.cgetter def val(cls): return cls._value
Use class-wide getter for instance too:
class Target(object): _value = 1 val = advanced_descriptors.AdvancedProperty() @val.cgetter def val(cls): return cls._value
Testing
The main test mechanism for the package advanced-descriptors is using tox. Available environments can be collected via tox -l
CI systems
For code checking several CI systems is used in parallel:
Travis CI: is used for checking: PEP8, pylint, bandit, installation possibility and unit tests. Also it’s publishes coverage on coveralls.
coveralls: is used for coverage display.
CD system
Travis CI: is used for package delivery on PyPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for Advanced-Descriptors-1.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55a4d1f8577bd5d19faa94cd2bd8782cd5df6ae78c2d255e647bbf2998dc2a76 |
|
MD5 | 919a7d473c151b79b3019ec488945ceb |
|
BLAKE2b-256 | 1ba1a9e3ddd6fa260a000fa492350cf0bf0a8bf7faca32fbd71e1d908b3efddf |
Hashes for Advanced_Descriptors-1.1.0-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 413f13b8d71e753ba8965fee4eb86a5fa455fb601fbe5bd2767e146d807cef8e |
|
MD5 | f507fc6881e4d4499967976069f149cc |
|
BLAKE2b-256 | 160846f8a541896d2ca58469022edb3ae970da863a68fbc0c16cfc04aba8b142 |