[issue24897] Add new attribute decorator (akin to property)?
Emanuel Barry
report at bugs.python.org
Thu Aug 20 03:41:59 CEST 2015
Emanuel Barry added the comment:
The only significant difference is that it lets the instance overwrite the attribute (it doesn't have __set__ or __delete__). For example (using fractions.Fraction to demonstrate), the following:
def __new__(cls, numerator=0, denominator=None, _normalize=True):
# ...
self._numerator = numerator
self._denominator = denominator
@property
def numerator(a):
return a._numerator
@property
def denominator(a):
return a._denominator
would become:
def __new__(cls, numerator=0, denominator=None, _normalize=True):
# ...
self.numerator = numerator
self.denominator = denominator
@attribute
def numerator(a):
pass
@attribute
def denominator(a):
pass
This is more of an aesthetic enhancement rather than a functional one.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24897>
_______________________________________
More information about the Python-bugs-list
mailing list