[Python-ideas] read-only attributes
K. Richard Pixley
rich at noir.com
Mon Jan 3 23:18:42 CET 2011
It seems to me that one of the more common reasons for using @property
is to create a read-only attribute. I wonder if it would make sense to
simply create a read-only decorator.
Compare:
class Foo(object):
_size = 4
@property
def size(self):
return _size
against:
class Foo(object):
@read-only
size = 4
This gets more interesting if decorators nest:
class Foo(object):
__metaclass__ = abc.ABCMeta
@abstract
@classattribute
@read-only
size = None
--rich
More information about the Python-ideas
mailing list