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

Uploaded Source

Built Distributions

Advanced_Descriptors-3.0.1-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

Advanced_Descriptors-3.0.1-cp37-cp37m-win_amd64.whl (125.1 kB view details)

Uploaded CPython 3.7m Windows x86-64

Advanced_Descriptors-3.0.1-cp37-cp37m-win32.whl (110.6 kB view details)

Uploaded CPython 3.7m Windows x86

Advanced_Descriptors-3.0.1-cp36-cp36m-win_amd64.whl (124.9 kB view details)

Uploaded CPython 3.6m Windows x86-64

Advanced_Descriptors-3.0.1-cp36-cp36m-win32.whl (110.4 kB view details)

Uploaded CPython 3.6m Windows x86

File details

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

File metadata

  • Download URL: Advanced-Descriptors-3.0.1.tar.gz
  • Upload date:
  • Size: 37.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for Advanced-Descriptors-3.0.1.tar.gz
Algorithm Hash digest
SHA256 a5a099e8cde204046b614cb8f0bd2f0b8248e47483d8cd45bd370b7c0010245e
MD5 cf18067c0bf8186d93a9fcc3ad3079ea
BLAKE2b-256 aa201d35a1a5072ac831e30bf2ca28583937195abd0b7f0eca4f5537101c83c7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Advanced_Descriptors-3.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for Advanced_Descriptors-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9126bf6ba197d2e597abc19dc0a87111b128d99e30638b943bdd253c8afb4afd
MD5 e1a04f8084c3cc6d86d1b2bc2e204dec
BLAKE2b-256 e860acd5c226499716aeb7025fd16878321712d023f73dded21415ac05373979

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Advanced_Descriptors-3.0.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 125.1 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

File hashes

Hashes for Advanced_Descriptors-3.0.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 cc84a845a2e1035cafca7d0f620fec9532562ece6dffb583e9a9474bbd391384
MD5 8a8f4ba11e9bd7f718a0b72ad58de82b
BLAKE2b-256 4c0b16af4a518423e44cfeaa3a5d89080de8689151c22765eedd551a465a64c8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Advanced_Descriptors-3.0.1-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 110.6 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

File hashes

Hashes for Advanced_Descriptors-3.0.1-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 b0ec7c322577d0bddbf709252ec5de2927bf3b40325f6a8cd18d639c8d885f48
MD5 5bd80b2b033eb4edda0197bcc4bcbcac
BLAKE2b-256 7ebe247826407d462df1dcf3a9b99efe65711e97350d2e9e9d8f4a806c08efd6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Advanced_Descriptors-3.0.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 4dd21c0a6fe47de2c7f45ddd3d2adc9871e6c43e26666e2f3f9fc495b4088f9d
MD5 510d37db690ab112a09571aa644d5736
BLAKE2b-256 41c7b989a8adb0bd4dc4e4de6542a0f977f0e6225c3f030cc8831ce307184d5f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Advanced_Descriptors-3.0.1-cp37-cp37m-manylinux1_i686.whl
  • Upload date:
  • Size: 435.1 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for Advanced_Descriptors-3.0.1-cp37-cp37m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 3585f8cac1eb9d3ee243294336c5931bdc230b2e7632b4f2447411e0f36ffa5c
MD5 d283d376a305fc945a30add1ef3f000a
BLAKE2b-256 23a74a3c387678e9d85bb5dfb65d15b7c2a67c68935a4ded4ce31fe358f57635

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Advanced_Descriptors-3.0.1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 124.9 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.4

File hashes

Hashes for Advanced_Descriptors-3.0.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 087d7eabd75ddaed812e51c1b7f441cdad1924dd1a2261b5359f7e093f974b0b
MD5 2e110fc43f23e62c2af625612b032f28
BLAKE2b-256 be4fe75a51f362329a592e0512dcfed401ec8d95f1e309d21f7efff60f159206

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Advanced_Descriptors-3.0.1-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 110.4 kB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.4

File hashes

Hashes for Advanced_Descriptors-3.0.1-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 fd462e8dea6ea92d835c155ac8f13252de766b9f0db5827a7f05fef5129f90bd
MD5 5a27a4d130a8e465e645bb55bf8f84dc
BLAKE2b-256 2fce35d783d7e618601c3aa05f8899357980b51219539c9bcbed70b79b14f448

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Advanced_Descriptors-3.0.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c48bd730a5611dcaf79e5fbb768f6779cd45757ce7355dafd60abe35c210b4c9
MD5 d520c72d8d8cd79a68ba50e8d375e6ec
BLAKE2b-256 969557b6283670f79f1f3bc83a5932f4bc3ee6bcf6679e0e3934af47c9b617d5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Advanced_Descriptors-3.0.1-cp36-cp36m-manylinux1_i686.whl
  • Upload date:
  • Size: 434.1 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for Advanced_Descriptors-3.0.1-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 06539ba08868e260243f849cef190ea4c82e7aa8f36abdcfea16c1d0c241e1cc
MD5 ee883ffeb739c17ef313a753806086af
BLAKE2b-256 9ab6a57baf4b182b4fe915be38f81f7f62fa04c6ef5a4d1fd1f40df5981730c4

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