https://github.com/serwy/fproperty
https://github.com/serwy/fproperty
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/serwy/fproperty
- Owner: serwy
- License: apache-2.0
- Created: 2020-08-08T21:21:02.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-08T23:47:51.000Z (about 5 years ago)
- Last Synced: 2025-02-15T14:05:33.094Z (8 months ago)
- Language: Python
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `fproperty` - a simpler property decorator
Define the `fget`/`fset`/`fdel` functions and return them:
from fproperty import fproperty
class Thing:
@fproperty
def my_attribute():def fget(self):
return self._attrdef fset(self, value):
self._attr = valuedef fdel(self):
del self._attrreturn (fget, fset, fdel, "doc")
instead of `property` chaining:
class Thing:
@property
def my_attribute(self):
return self._attr@my_attribute.setter
def my_attribute(self, value):
self._attr = value@my_attribute.deleter
def my_attribute(self):
del self._attrwhich requires typing `my_attribute` five times,
or by using the non-decorator case:class Thing:
def fget(self):
return self._attrdef fset(self, value):
self._attr = valuedef fdel(self):
del self._attrmy_attribute = property(fget, fset, fdel, "doc")
del fget, fset, fdelwhich spreads out the definitions, and requires
namespace cleanup.## Other examples
The `fproperty` decorator can be returned a partial list:
@fproperty
def set_only_attribute():
def fset(self, value):
self._value = value
return (None, fset)## `@property.apply`
The `property` builtin can be substituted, and has `.apply`:
from fproperty import property
class Thing:
@property.apply
def attr():
def g(self): pass
return (g, )## Install
pip install fproperty
or define it yourself:
def fproperty(func):
return property(*func())## License
Licensed under the Apache License, Version 2.0 (the "License")