diff options
author | Raymond Hettinger <python@rcn.com> | 2013-03-10 16:42:22 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2013-03-10 16:42:22 (GMT) |
commit | e238b889eb3fb035775ef71d359058c64f4479f9 (patch) | |
tree | 2c1fa5b92e673a19b003e45a56411a7eebaeeab9 /Doc/howto | |
parent | 081a55b09049f67bcd71d367645a91541ae4454d (diff) | |
parent | 632c8c8ab114290e876c14452a803795cce432a3 (diff) | |
download | cpython-e238b889eb3fb035775ef71d359058c64f4479f9.zip cpython-e238b889eb3fb035775ef71d359058c64f4479f9.tar.gz cpython-e238b889eb3fb035775ef71d359058c64f4479f9.tar.bz2 |
merge
Diffstat (limited to 'Doc/howto')
-rw-r--r-- | Doc/howto/descriptor.rst | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/Doc/howto/descriptor.rst b/Doc/howto/descriptor.rst index 0b513f9..923bbe8 100644 --- a/Doc/howto/descriptor.rst +++ b/Doc/howto/descriptor.rst @@ -210,25 +210,36 @@ here is a pure Python equivalent:: self.fget = fget self.fset = fset self.fdel = fdel + if doc is None and fget is not None: + doc = fget.__doc__ self.__doc__ = doc def __get__(self, obj, objtype=None): if obj is None: return self if self.fget is None: - raise AttributeError, "unreadable attribute" + raise AttributeError("unreadable attribute") return self.fget(obj) def __set__(self, obj, value): if self.fset is None: - raise AttributeError, "can't set attribute" + raise AttributeError("can't set attribute") self.fset(obj, value) def __delete__(self, obj): if self.fdel is None: - raise AttributeError, "can't delete attribute" + raise AttributeError("can't delete attribute") self.fdel(obj) + def getter(self, fget): + return type(self)(fget, self.fset, self.fdel, self.__doc__) + + def setter(self, fset): + return type(self)(self.fget, fset, self.fdel, self.__doc__) + + def deleter(self, fdel): + return type(self)(self.fget, self.fset, fdel, self.__doc__) + The :func:`property` builtin helps whenever a user interface has granted attribute access and then subsequent changes require the intervention of a method. |