Skip to main content

Advanced descriptors for special cases.

Project description

Advanced descriptors

https://travis-ci.org/python-useful-helpers/advanced-descriptors.svg?branch=master Azure DevOps builds https://coveralls.io/repos/github/python-useful-helpers/advanced-descriptors/badge.svg?branch=master Documentation Status https://img.shields.io/pypi/v/advanced-descriptors.svg https://img.shields.io/pypi/pyversions/advanced-descriptors.svg https://img.shields.io/pypi/status/advanced-descriptors.svg https://img.shields.io/github/license/python-useful-helpers/advanced-descriptors.svg https://img.shields.io/badge/code%20style-black-000000.svg

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.

  • LogOnAccess - property with logging on successful get/set/delete or failure.

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:

  1. 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
  1. Use class-wide getter for instance too:

class Target(object):
    _value = 1

    val = advanced_descriptors.AdvancedProperty()

    @val.cgetter
        def val(cls):
            return cls._value

LogOnAccess

This special case of property is useful in cases, where a lot of properties should be logged by similar way without writing a lot of code.

Basic API is conform with property, but in addition it is possible to customize logger, log levels and log conditions.

Usage examples:

  1. Simple usage. All by default, logger is re-used from instance if available with names logger or log else used internal advanced_descriptors.log_on_access logger:

import logging

class Target(object):

    def init(self, val='ok')
        self.val = val
        self.logger = logging.get_logger(self.__class__.__name__)  # Single for class, follow subclassing

    def __repr__(self):
        return "{cls}(val={self.val})".format(cls=self.__class__.__name__, self=self)

    @advanced_descriptors.LogOnAccess
    def ok(self):
        return self.val

    @ok.setter
    def ok(self, val):
        self.val = val

    @ok.deleter
    def ok(self):
        self.val = ""
  1. Use with global logger for class:

class Target(object):

  def init(self, val='ok')
      self.val = val

  def __repr__(self):
      return "{cls}(val={self.val})".format(cls=self.__class__.__name__, self=self)

  @advanced_descriptors.LogOnAccess
  def ok(self):
      return self.val

  @ok.setter
  def ok(self, val):
      self.val = val

  @ok.deleter
  def ok(self):
      self.val = ""

  ok.logger = 'test_logger'
  ok.log_level = logging.INFO
  ok.exc_level = logging.ERROR
  ok.log_object_repr = True  # As by default
  ok.log_success = True  # As by default
  ok.log_failure = True  # As by default
  ok.log_traceback = True  # As by default
  ok.override_name = None  # As by default: use original name

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:

  1. Travis CI: is used for checking: PEP8, pylint, bandit, installation possibility and unit tests. Also it’s publishes coverage on coveralls.

  2. coveralls: is used for coverage display.

  3. Azure CI: is used for functional tests on Windows.

CD system

Travis CI: is used for package delivery on PyPI.

Project details


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-2.2.4.tar.gz (44.3 kB view details)

Uploaded Source

Built Distributions

Advanced_Descriptors-2.2.4-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

Advanced_Descriptors-2.2.4-cp37-cp37m-win_amd64.whl (123.9 kB view details)

Uploaded CPython 3.7m Windows x86-64

Advanced_Descriptors-2.2.4-cp37-cp37m-win32.whl (109.0 kB view details)

Uploaded CPython 3.7m Windows x86

Advanced_Descriptors-2.2.4-cp36-cp36m-win_amd64.whl (123.7 kB view details)

Uploaded CPython 3.6m Windows x86-64

Advanced_Descriptors-2.2.4-cp36-cp36m-win32.whl (108.8 kB view details)

Uploaded CPython 3.6m Windows x86

Advanced_Descriptors-2.2.4-cp35-cp35m-win_amd64.whl (114.5 kB view details)

Uploaded CPython 3.5m Windows x86-64

Advanced_Descriptors-2.2.4-cp35-cp35m-win32.whl (100.0 kB view details)

Uploaded CPython 3.5m Windows x86

File details

Details for the file Advanced-Descriptors-2.2.4.tar.gz.

File metadata

  • Download URL: Advanced-Descriptors-2.2.4.tar.gz
  • Upload date:
  • Size: 44.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 PyPy/5.10.1

File hashes

Hashes for Advanced-Descriptors-2.2.4.tar.gz
Algorithm Hash digest
SHA256 5e0814d546412f04aa8e930beb42eb45743ad746dc179d4ba43b9ecd2d1e48ca
MD5 9ea370df02520d3bfa81c4ce524df51b
BLAKE2b-256 b3e44c279c361c2af81def6cc850fd6d5d0f498a50c56bc3b640502119ac6f6b

See more details on using hashes here.

File details

Details for the file Advanced_Descriptors-2.2.4-py3-none-any.whl.

File metadata

  • Download URL: Advanced_Descriptors-2.2.4-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.4.4

File hashes

Hashes for Advanced_Descriptors-2.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fcdaebbae59d149e7c60416dcd449bc51fc619f905526fc87eac664e3afbf624
MD5 513ce9a63b6cc9db924598f316af24bf
BLAKE2b-256 b88693c87fe590df0a1687534d5d2b42e22ee9dcb3e0f9462dd8441efe135e91

See more details on using hashes here.

File details

Details for the file Advanced_Descriptors-2.2.4-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: Advanced_Descriptors-2.2.4-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 123.9 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for Advanced_Descriptors-2.2.4-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 6a76996f92bf6b41251649e8358ff3982e46fe2e6131f287ea3e91829a71a272
MD5 4bfd893de042ca9dfc2d3f12088b9876
BLAKE2b-256 a5c6c774c03f51dd8cd9283925c39a4c316ac0554b9256c279b1b5ffad6b7fd2

See more details on using hashes here.

File details

Details for the file Advanced_Descriptors-2.2.4-cp37-cp37m-win32.whl.

File metadata

  • Download URL: Advanced_Descriptors-2.2.4-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 109.0 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for Advanced_Descriptors-2.2.4-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 979cc5b3bd32478a8b2f3a32c5e27d9c26cbaaab61f8e1560ce0f8928d0da9cc
MD5 ab1ca255af3b2f76c6d8aeb78d1edc22
BLAKE2b-256 cc6efc601c32a6869e24251bf9c686cf147d629df3107f95ff9f6430002ef446

See more details on using hashes here.

File details

Details for the file Advanced_Descriptors-2.2.4-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for Advanced_Descriptors-2.2.4-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 1220c21abe98a93b4e692b160383d78a115ee75e4db3658d1dfc7ea656ce17df
MD5 c2f2bc734341d98e95e95c32460e45e0
BLAKE2b-256 174fd741a139066efab5373f4a713bacccb813a413298959906e979834dece0f

See more details on using hashes here.

File details

Details for the file Advanced_Descriptors-2.2.4-cp37-cp37m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for Advanced_Descriptors-2.2.4-cp37-cp37m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 3b1b26d04ac974bb2649c0798d7ba4df2adb241464eafb782d22fde93ae4cad0
MD5 6973edf2f387eef1753de745c3edeeac
BLAKE2b-256 dad6d93c784b40fc4063b17230f4706ea9d4cec822520f3408da703349c70c65

See more details on using hashes here.

File details

Details for the file Advanced_Descriptors-2.2.4-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: Advanced_Descriptors-2.2.4-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 123.7 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4

File hashes

Hashes for Advanced_Descriptors-2.2.4-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 97e6e74f2952d910a8715a797a6cb36c319953ae5460ee6c813db1a01201f582
MD5 ccba984e8b24af9302cf76456deab6c3
BLAKE2b-256 b699aaba0f4241729acf4f79e0f2f5bf2b20231e6701145cf8f2eb5c46e35a0a

See more details on using hashes here.

File details

Details for the file Advanced_Descriptors-2.2.4-cp36-cp36m-win32.whl.

File metadata

  • Download URL: Advanced_Descriptors-2.2.4-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 108.8 kB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4

File hashes

Hashes for Advanced_Descriptors-2.2.4-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 0acbc4b8b58352d6b95716af9136cfbda8b7c4a08b65b2c2526533b5aab5932d
MD5 837425f8f3079ed76044c2bcc5df3c16
BLAKE2b-256 00f4bf538fddcfbca1d44392304941692f024a0b858300558b49f5a628c5f230

See more details on using hashes here.

File details

Details for the file Advanced_Descriptors-2.2.4-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for Advanced_Descriptors-2.2.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f58ce38762288a2297492bbe5b78b64f0a1c48dd458bc216a45a932eedc094d8
MD5 054784094e7d2dd8af807c2b85ca7853
BLAKE2b-256 98ee9622a73e31c35aec06847324940959d23287383f36280015d7ce952bc892

See more details on using hashes here.

File details

Details for the file Advanced_Descriptors-2.2.4-cp36-cp36m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for Advanced_Descriptors-2.2.4-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 16dbe098d1082a095d54ffd5650751e82b374164a5789bccc3f23747536f0d4f
MD5 9e2ea1f67e120b17b3a35436781f8bdf
BLAKE2b-256 1f9a33105176ba4fab1dab7bc52d44d23487c32d3feb641f51d5a63fa63351f0

See more details on using hashes here.

File details

Details for the file Advanced_Descriptors-2.2.4-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: Advanced_Descriptors-2.2.4-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 114.5 kB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.4

File hashes

Hashes for Advanced_Descriptors-2.2.4-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 1dc587aeef0a605b1d1de347ca157f9e3daacea506483405034dd9fe49ed16aa
MD5 92d889fdc2d3d866e4229b1bc76075f7
BLAKE2b-256 5431d47bbd5319beccf075e217e90441702c9e9d908f28f9162e1bf192589b80

See more details on using hashes here.

File details

Details for the file Advanced_Descriptors-2.2.4-cp35-cp35m-win32.whl.

File metadata

  • Download URL: Advanced_Descriptors-2.2.4-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 100.0 kB
  • Tags: CPython 3.5m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.4

File hashes

Hashes for Advanced_Descriptors-2.2.4-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 fa11adcecb6307e34f73744363d0c20437454f4f10ee734c4cc528827e171dc7
MD5 98069b6f5a7be07b9a7f0776a456526c
BLAKE2b-256 d5dad503be2ca608563c156a87f9a7c08aab01dcd9c2840060eac509b24ee02a

See more details on using hashes here.

File details

Details for the file Advanced_Descriptors-2.2.4-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for Advanced_Descriptors-2.2.4-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 abeee2dd57419b9a8eb1ebe5b80ab777b2c07e020c8261e5cf0b657258aaeb10
MD5 a968db53e8aeaa0fe9a1c666e0e5c4b9
BLAKE2b-256 05bf20eab1d6332a7b9dc47aa062166d8000dc72290576f49a11680235da4204

See more details on using hashes here.

File details

Details for the file Advanced_Descriptors-2.2.4-cp35-cp35m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for Advanced_Descriptors-2.2.4-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 b681616cc3a684e7685018a3a0d8e66cf33d1ba7653340732f1633461901989f
MD5 bb44604a40739bc27a9dd4b950d020c9
BLAKE2b-256 ba2a533fcbadab236e6d9a3176febb12432841eb361894b2e2d2ad5d2edf1084

See more details on using hashes here.

File details

Details for the file Advanced_Descriptors-2.2.4-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for Advanced_Descriptors-2.2.4-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 9e56b4526fc69cb2701ca5511288a18516e6cac788a2c72a9b2876e10b33bcc8
MD5 44f7382d81b35f748c45b5f635d2eec6
BLAKE2b-256 2327e4e51967f266a093606260c6527346e62348911ae7f66b6db3a34365b4e4

See more details on using hashes here.

File details

Details for the file Advanced_Descriptors-2.2.4-cp34-cp34m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for Advanced_Descriptors-2.2.4-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 f965f8dcdc97d1bde6ae372e395fcde35d7d34e1404b4f93b56745b05affa3ec
MD5 7a6cfd2f33043d7ff3917e3d1772409e
BLAKE2b-256 33517335bc3616abcb315637b2153a74d6c51f40cab9c20f995d62af964d3e60

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page