diff options
Diffstat (limited to 'Doc/howto')
-rw-r--r-- | Doc/howto/descriptor.rst | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/Doc/howto/descriptor.rst b/Doc/howto/descriptor.rst index ab5a573..d172c9b 100644 --- a/Doc/howto/descriptor.rst +++ b/Doc/howto/descriptor.rst @@ -934,32 +934,42 @@ here is a pure Python equivalent: if doc is None and fget is not None: doc = fget.__doc__ self.__doc__ = doc + self._name = '' + + def __set_name__(self, owner, name): + self._name = name def __get__(self, obj, objtype=None): if obj is None: return self if self.fget is None: - raise AttributeError("unreadable attribute") + raise AttributeError(f'unreadable attribute {self._name}') return self.fget(obj) def __set__(self, obj, value): if self.fset is None: - raise AttributeError("can't set attribute") + raise AttributeError(f"can't set attribute {self._name}") self.fset(obj, value) def __delete__(self, obj): if self.fdel is None: - raise AttributeError("can't delete attribute") + raise AttributeError(f"can't delete attribute {self._name}") self.fdel(obj) def getter(self, fget): - return type(self)(fget, self.fset, self.fdel, self.__doc__) + prop = type(self)(fget, self.fset, self.fdel, self.__doc__) + prop._name = self._name + return prop def setter(self, fset): - return type(self)(self.fget, fset, self.fdel, self.__doc__) + prop = type(self)(self.fget, fset, self.fdel, self.__doc__) + prop._name = self._name + return prop def deleter(self, fdel): - return type(self)(self.fget, self.fset, fdel, self.__doc__) + prop = type(self)(self.fget, self.fset, fdel, self.__doc__) + prop._name = self._name + return prop .. testcode:: :hide: |