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 🏫
- Host: GitHub
- URL: https://github.com/rec/clsprop
- Owner: rec
- Created: 2023-04-11T09:24:43.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-14T14:42:16.000Z (almost 2 years ago)
- Last Synced: 2024-05-01T19:20:41.961Z (over 1 year ago)
- Topics: decorators, decorators-python, properties, python
- Language: Python
- Homepage: https://rec.github.io/clsprop/
- Size: 579 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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)