An open API service indexing awesome lists of open source software.

https://github.com/rec/clsprop

🏫 Like property but for classes 🏫
https://github.com/rec/clsprop

decorators decorators-python properties python

Last synced: 9 months ago
JSON representation

🏫 Like property but for classes 🏫

Awesome Lists containing this project

README

          

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](https://rec.github.io/clsprop#clsprop--api-documentation)