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

Uploaded Source

Built Distributions

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

Uploaded Python 3

Advanced_Descriptors-3.0.0-cp37-cp37m-win_amd64.whl (125.2 kB view details)

Uploaded CPython 3.7m Windows x86-64

Advanced_Descriptors-3.0.0-cp37-cp37m-win32.whl (110.5 kB view details)

Uploaded CPython 3.7m Windows x86

Advanced_Descriptors-3.0.0-cp36-cp36m-win_amd64.whl (124.8 kB view details)

Uploaded CPython 3.6m Windows x86-64

Advanced_Descriptors-3.0.0-cp36-cp36m-win32.whl (110.2 kB view details)

Uploaded CPython 3.6m Windows x86

File details

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

File metadata

  • Download URL: Advanced-Descriptors-3.0.0.tar.gz
  • Upload date:
  • Size: 37.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for Advanced-Descriptors-3.0.0.tar.gz
Algorithm Hash digest
SHA256 2df092f1bad64bc9c22bbc0a045f5054fb71faeda5d713d5fe7ef6e2794d53d9
MD5 da73c0a720d239d67e47c47f78e5918c
BLAKE2b-256 e21074e98e1d2549a10290187254dd6e8936521fb61c8eba8b07e9ba10a04259

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Advanced_Descriptors-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for Advanced_Descriptors-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3cff3fae846089f20044fd9e23f2a703a395402e2ce8e2dd6373a19d7d9cc743
MD5 5d618bf7a4698986d0eaa5c438141848
BLAKE2b-256 fd8caddfee43eeb12c8c483e51fddbd6111d863b85d2c93107b84cb271124aa4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Advanced_Descriptors-3.0.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 125.2 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.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for Advanced_Descriptors-3.0.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 752b30646268903e875c985d468d83c82336a450f4dff91527640a072ab21fa0
MD5 1b4c714466e183609ececf1d49120df5
BLAKE2b-256 3088b281c0a4004fec84d73ac9cbf4f7504adfecb7f146ec38b21021885ec99e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for Advanced_Descriptors-3.0.0-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 67557d42f80e459678eeb838d368cf506fc6837f307fa3dc2a210f55f55ff226
MD5 0210c2f3a611370b023e996ddffea806
BLAKE2b-256 ec1efa3fd3c11f3737d7098295b0833f73a5a03f2567fe808512654bac7f6631

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Advanced_Descriptors-3.0.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 2bf4d1f24df3119a997046b299efd3e6637df131f386c2cdc70f2f81971526fc
MD5 c919321085ab29cb0fee8ac0d283a017
BLAKE2b-256 297cd229d1899d509d1e48de2708f506a08236556f66c54695178178b0e8ce27

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Advanced_Descriptors-3.0.0-cp37-cp37m-manylinux1_i686.whl
  • Upload date:
  • Size: 434.6 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for Advanced_Descriptors-3.0.0-cp37-cp37m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 4ed2e6d42557a6d527a0c7e5df87fbe64d7ac1d2db00ed09a542b914d99a2149
MD5 f7fcb9de227be01be6e446ca7f280860
BLAKE2b-256 0be87de5b35e809fde3a19964289aabfdb88a826263b407cffdf74ca585fbd9b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Advanced_Descriptors-3.0.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 124.8 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.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4

File hashes

Hashes for Advanced_Descriptors-3.0.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 199969a260ced746f67757652d8f789b55779f23d18e88231ad997026440733e
MD5 c758bdbaf5b8aa55ec13f02e3590c394
BLAKE2b-256 6d18ca696bda448c4c6b4e0fb7d75a6b874f79a9617394e9b55db48a52844c27

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for Advanced_Descriptors-3.0.0-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 a493a0d5c15e948a36abc303193f352fef003889d98a46eb8d1150bc3a6c73f1
MD5 abe3a773fca62f90a701e7434925bb2c
BLAKE2b-256 9bfee5995dd5dd1bc805d6715e6a29f2efa13c384d2ae4c051269b5d82c2f736

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Advanced_Descriptors-3.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b92bfafec0a058f04a413a53bc3dac4340c85c1bb15beb448052df96d4455042
MD5 a7d47feda3ef6bbcb53e3462e18ce7c1
BLAKE2b-256 4c6e781249c558a7540731bdd1b1ac60c2a7fc348179364cca81b0ffb4f99d77

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Advanced_Descriptors-3.0.0-cp36-cp36m-manylinux1_i686.whl
  • Upload date:
  • Size: 433.9 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for Advanced_Descriptors-3.0.0-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 dd409e57cbffd7a336de6dbe90a146ee996ee5beb28470bc0500abf13193bd6c
MD5 fcd48a6a4fb6b68f943459de5893605f
BLAKE2b-256 7df7ef426835c38bd786691d9166c00d0fea8cda7035f6a18b207f9fa5ef0e9f

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