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 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 example:

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.

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

Uploaded Source

Built Distributions

Advanced_Descriptors-2.1.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: Advanced-Descriptors-2.1.0.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 PyPy/5.10.1

File hashes

Hashes for Advanced-Descriptors-2.1.0.tar.gz
Algorithm Hash digest
SHA256 022e2dd2837959f9a7edd8c838fe141d873e95c1d857789ce3266fa65c6966f5
MD5 d061d61f89ceb923409598ec779e32d9
BLAKE2b-256 e7102f347fc35cbc7b069e1607dc21698da1b6df20b62ac971d40b1888ac4b6a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Advanced_Descriptors-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 PyPy/5.10.1

File hashes

Hashes for Advanced_Descriptors-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b2085831b28b2a3e87ff24f1604aff0b391de2a9fa71896d7bb68e4bbd27be1
MD5 8870f50f30c6da40966247727ab0e2fe
BLAKE2b-256 33bdb986c3bca3427f3d894d6e0478c7035b5919b4f6c23622d42d7ed964c507

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Advanced_Descriptors-2.1.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e876485517ef5ac5c500bd5b722781cc0b8cff4c35c02414de1c1ba222277685
MD5 b5c19049dbec1be3a139221b403cf9ef
BLAKE2b-256 4ba2e87c0f02ec38516b372cc26b9fa2aec7df408b4a0c5e9fd6406d5ad42f6d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Advanced_Descriptors-2.1.0-cp37-cp37m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 4e74dda6e82a23e56162f52d91d415a83d822f144d4cf4e462d7550be029d13c
MD5 bea6c995b7de28dfd8f8d651dc988b1f
BLAKE2b-256 65c01cbfe78092865a302df9a80a35d08b84185059db96bdec3b542193b8c8b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Advanced_Descriptors-2.1.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b401c31d23c123ffcb98a7bc192d63404c1e73f7a4c0a3457fc96bf6791f6237
MD5 997afde002a8cac17cb95e9525e8698d
BLAKE2b-256 5a4084d610d794d4cc7ed1f7ab8e80657665bfd153a2b98cfe8054241a72bd0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Advanced_Descriptors-2.1.0-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 b187a80b04619e2d8b45bf5f750568f2d2c3c8e0aa82172d578e49dca9cb341c
MD5 fe596dd4499d36e2ad01d52b6175744d
BLAKE2b-256 13888032ab6ca3527fb6c394af00209566d07b977c1e33bc98d4ef536f7a5413

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Advanced_Descriptors-2.1.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 91b25453ff3dd0c3706f62c27cbdec9a3a40fdaa32b1bafd5199aa736993353b
MD5 b8758b96c74037238d1cf5736fcb348e
BLAKE2b-256 1a85e1d40a803df181b514cb409aa81616f8cae98491010770d65d1ad1b6b30e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Advanced_Descriptors-2.1.0-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 2dde99d2a1436249a1ff333713241571b8d514ba3137e57116d3a59213c69057
MD5 fbbba571f4734db4f2cc44700711eaaf
BLAKE2b-256 6e7536bd9d0c26b0dc51468d667e905efcbb5d42f626b83b0be37f3cc44d02f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Advanced_Descriptors-2.1.0-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f6f01ffb7b6d0e11060a45caac8ca8b5150213494d398be495eb63a99b6f6e86
MD5 3c300ebfeb6cb709ff58e23ce71961d6
BLAKE2b-256 cecfd4e345cd18931439bf8e8bf4e9153c5f429a29fa6b142b15f78d68837bf3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Advanced_Descriptors-2.1.0-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 415cfc0dcc2443e211976f4b2dd67aa1bd5fd3c7d6b6f204a14be49565ea11a9
MD5 cfa2f5ae912befeccd120bb29eb64ca1
BLAKE2b-256 069072aca57897697607f8d6b403c3c77d69b2af71a9c742be115dbe36c1141f

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