Skip to main content

Additional Python decorators implementing the descriptor interface.

Use cases

Like the built-in decorator, property, these classes are initialized by and wrap a function, generally within the context of a class, in order to modify its behavior.

cached property

This decorator functions much like a read-only property, with the difference that, upon access, it records its result in the instance’s object data dictionary, which reference takes precedence in look-ups, thereby replacing itself for that object:

from descriptors import cachedproperty

@cachedproperty
def circumference(self):
    return 2 * math.pi * self.radius

class property

A read-only property for class methods:

from descriptors import classproperty

@classproperty
def badpi(cls):
    return 22 / 7

cached class property

A class property, which caches its result in the data dictionary of the class from which it was invoked, (under another name, so as not to interfere with inheritance of the property):

from descriptors import cachedclassproperty

@cachedclassproperty
def badpi(cls):
    return 22 / 7

class-only method

A class method that cannot be accessed as an instance method:

from descriptors import classonlymethod

@classonlymethod
def circumference(cls, radius):
    return 2 * cls.pi * radius

The class-only method may be overshadowed by instance data set under the same name.

Otherwise, instance access raises AttributeError (and such that it is forwarded to and may be handled by the instance’s __getattr__).

Installation

Dickens is a Python distribution, which may be installed via easy_install or pip, e.g.:

pip install Dickens

…or, from source:

python setup.py install

Metadata

Release files for Dickens 2.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Dickens 2.1.1
File Size Uploaded
Dickens-2.1.1.tar.gz 3.4 kB Details

Release files / Dickens-2.1.1.tar.gz

Download URL Dickens-2.1.1.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
54d2d831ee6980d57477b9236b3ced27fccf0d8527d332bb84c295fcedf06a7b
BLAKE2b-256 checksum
How to use checksums
068cb5564ba0a70630fec923dbc9216efb1e8dadfba157e75f7ea51e3e37a646
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release history Release notifications | RSS feed

This release

2.1.1 This release

1 release file

2.1.0

1 release file

2.0.0

1 release file

1.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page