Advanded descriptors for special cases.
Project description
Advanced descriptors
====================
.. image:: https://travis-ci.org/penguinolog/advanced-descriptors.svg?branch=master
:target: https://travis-ci.org/penguinolog/advanced-descriptors
.. image:: https://coveralls.io/repos/github/penguinolog/advanced-descriptors/badge.svg?branch=master
:target: https://coveralls.io/github/penguinolog/advanced-descriptors?branch=master
.. image:: https://img.shields.io/pypi/v/advanced-descriptors.svg
:target: https://pypi.python.org/pypi/advanced-descriptors
.. image:: https://img.shields.io/pypi/pyversions/advanced-descriptors.svg
:target: https://pypi.python.org/pypi/advanced-descriptors
.. image:: https://img.shields.io/pypi/status/advanced-descriptors.svg
:target: https://pypi.python.org/pypi/advanced-descriptors
.. image:: https://img.shields.io/github/license/penguinolog/advanced-descriptors.svg
:target: https://raw.githubusercontent.com/penguinolog/advanced-descriptors/master/LICENSE
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:
.. code-block:: python
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:
.. code-block:: python
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.
.. note::
classmethod receives class as argument. IDE's don't know about custom descriptors and substitutes `self` by default.
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:
1. In addition to normal property API:
.. code-block:: python
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
2. Use class-wide getter for instance too:
.. code-block:: python
class Target(object):
_value = 1
val = advanced_descriptors.AdvancedProperty()
@val.cgetter
def val(cls):
return cls._value
.. note::
class-wide getter receives class as argument. IDE's don't know about custom descriptors and substitutes `self` by default.
Testing
=======
The main test mechanism for the package `advanced-descriptors` is using `tox`.
Test environments available:
::
pep8
py27
py34
py35
py36
pypy
pypy3
pylint
pep257
CI systems
==========
For code checking several CI systems is used in parallel:
1. `Travis CI: <https://travis-ci.org/penguinolog/advanced-descriptors>`_ is used for checking: PEP8, pylint, bandit, installation possibility and unit tests. Also it's publishes coverage on coveralls.
2. `coveralls: <https://coveralls.io/github/penguinolog/advanced-descriptors>`_ is used for coverage display.
CD system
=========
`Travis CI: <https://travis-ci.org/penguinolog/logwrap>`_ is used for package delivery on PyPI.
====================
.. image:: https://travis-ci.org/penguinolog/advanced-descriptors.svg?branch=master
:target: https://travis-ci.org/penguinolog/advanced-descriptors
.. image:: https://coveralls.io/repos/github/penguinolog/advanced-descriptors/badge.svg?branch=master
:target: https://coveralls.io/github/penguinolog/advanced-descriptors?branch=master
.. image:: https://img.shields.io/pypi/v/advanced-descriptors.svg
:target: https://pypi.python.org/pypi/advanced-descriptors
.. image:: https://img.shields.io/pypi/pyversions/advanced-descriptors.svg
:target: https://pypi.python.org/pypi/advanced-descriptors
.. image:: https://img.shields.io/pypi/status/advanced-descriptors.svg
:target: https://pypi.python.org/pypi/advanced-descriptors
.. image:: https://img.shields.io/github/license/penguinolog/advanced-descriptors.svg
:target: https://raw.githubusercontent.com/penguinolog/advanced-descriptors/master/LICENSE
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:
.. code-block:: python
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:
.. code-block:: python
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.
.. note::
classmethod receives class as argument. IDE's don't know about custom descriptors and substitutes `self` by default.
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:
1. In addition to normal property API:
.. code-block:: python
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
2. Use class-wide getter for instance too:
.. code-block:: python
class Target(object):
_value = 1
val = advanced_descriptors.AdvancedProperty()
@val.cgetter
def val(cls):
return cls._value
.. note::
class-wide getter receives class as argument. IDE's don't know about custom descriptors and substitutes `self` by default.
Testing
=======
The main test mechanism for the package `advanced-descriptors` is using `tox`.
Test environments available:
::
pep8
py27
py34
py35
py36
pypy
pypy3
pylint
pep257
CI systems
==========
For code checking several CI systems is used in parallel:
1. `Travis CI: <https://travis-ci.org/penguinolog/advanced-descriptors>`_ is used for checking: PEP8, pylint, bandit, installation possibility and unit tests. Also it's publishes coverage on coveralls.
2. `coveralls: <https://coveralls.io/github/penguinolog/advanced-descriptors>`_ is used for coverage display.
CD system
=========
`Travis CI: <https://travis-ci.org/penguinolog/logwrap>`_ 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
Advanced-Descriptors-0.5.1.tar.gz
(107.1 kB
view hashes)
Built Distributions
Close
Hashes for Advanced-Descriptors-0.5.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccdd1f1d5a4bcff44f3a9f028d7e55169198ad0bc14f185943d0c95f13761706 |
|
MD5 | 1bb81dd3d57e98cf444b8402a41aebc7 |
|
BLAKE2b-256 | 6882b8101f71b1b7298d86179fe99c8a105b1ede6b8033145f6cabd886120381 |
Close
Hashes for Advanced_Descriptors-0.5.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3f5407ddfce58103abfb53bca5d2fcdd138fe2f4af2a8e8363030f7cde9b45f |
|
MD5 | 3ce7a8fbed586c5805e1831949962661 |
|
BLAKE2b-256 | c0cf63816373acab9aef8cbf6cd3583521c3bcd75e6928ec20517e1229374ae0 |
Close
Hashes for Advanced_Descriptors-0.5.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0901f82830e8598f35ec6d9e09a0d02ca3a6d8d6c713cb49a2947185c4211e01 |
|
MD5 | aa7e5efae706fb6ad7d47c8596081c5a |
|
BLAKE2b-256 | d79b50356d73938ccb741403c131e8395003ace9af9d68d68f0f8fb33d68f86f |
Close
Hashes for Advanced_Descriptors-0.5.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 497ef4c735fef3c28e58fa918ccbb3f481ad24aa5009d223512fe3509cdc1c39 |
|
MD5 | 608023e7da65f77cfa56992bfac2344f |
|
BLAKE2b-256 | 5add8492e2d59b858da4925afb1099eb794a245ee455cf23cc5dfaf58508402b |
Close
Hashes for Advanced_Descriptors-0.5.1-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20c44072eb25dea74ff11971a977ccd8818d187ebaafe6af112d3d87c0e79b0f |
|
MD5 | 6a61ab2c92512caee4c304eaf5218a8d |
|
BLAKE2b-256 | 7414cdbf4516420d58531ce2d41d81a1455984ab1b7ec879fced7ba4878e09bc |
Close
Hashes for Advanced_Descriptors-0.5.1-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 031c8e24b4b6cc9f148a09a5521dbc2fbc008c14c724c11dad9d04daf54dcb81 |
|
MD5 | db153601be8722553d000138748de957 |
|
BLAKE2b-256 | 92c6977bcfb33faff6c8565e0be433c12524dc0513aa87ecc0abbe3f5e0fbe3f |
Close
Hashes for Advanced_Descriptors-0.5.1-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4d95817f97c770832a8cb20285281a2ab698a1f4a5da1c06b728e0612adb266 |
|
MD5 | 390757351908c82ee1e6709645f7e825 |
|
BLAKE2b-256 | a2cc9f2bbd1dca74b0d280a56ccbbc88869d17b440b6005271c8a8cf6c14c2a6 |
Close
Hashes for Advanced_Descriptors-0.5.1-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf84d5d89c3194d26945f01bf158492fb4de4a0b6d4de507ca8e16167eb96277 |
|
MD5 | 61fefa6ccfbb3cd5ca0f027801425bc7 |
|
BLAKE2b-256 | 60451920d8151c64de7c4a8fdb7348fd2113ed7a6cb8a3035013a45be43da760 |
Close
Hashes for Advanced_Descriptors-0.5.1-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd92289724befff7d9636d53248634dd74a33af9dacca034f091e5bd320da5d8 |
|
MD5 | 009294545525f3be8f42d14ff3aa45f6 |
|
BLAKE2b-256 | 2b1f4218cf4341265a10ced05f420e8b6422d308390b4bb903719b1c56321604 |
Close
Hashes for Advanced_Descriptors-0.5.1-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b627843e87a173dfa5c87902f839cb60b6838207854c1f9ab3e1bce6b7babde |
|
MD5 | 682646d03dd891c5fb5ac7c631bc0993 |
|
BLAKE2b-256 | 7e226eb11b973ab2ac96ef16bd8e3cf17260b9423989426d2f350fa1e3ea94f3 |
Close
Hashes for Advanced_Descriptors-0.5.1-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb2a536de993cc3d55242faa95f267730f55fda824b0c0146bed80149e4db651 |
|
MD5 | c616cdebab0c918a8963d6ef13536b7d |
|
BLAKE2b-256 | 95022659c25f6128a09668385d1263030ade328ee594b0ef80c7e8afd2a687fa |