Skip to main content

🏫 Just like @property but for classes 🏫

Project description

Works just like @property for classes, except deleters don't work (and are perhaps impossible).

Inspired by https://stackoverflow.com/a/39542816/43839

Example

import clsprop

class Full:
    _name = 'fool'

    @clsprop
    def name(cls):
        return cls._name

    @name.setter
    def name(cls, name):
        cls._name = name

    # Unfortunately, the deleter never gets called
    @name.deleter
    def name(cls, name):
        raise ValueError('Cannot delete name')

assert Full.name == 'fool'

Full.name = 'foll'
assert Full.name == 'foll'

del Full.name  # oh, well

API Documentation

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

clsprop-1.3.1.tar.gz (1.6 kB view hashes)

Uploaded Source

Built Distribution

clsprop-1.3.1-py3-none-any.whl (2.2 kB view hashes)

Uploaded Python 3

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