mirror of
https://github.com/python/cpython.git
synced 2025-11-02 19:12:55 +00:00
Document that @property can incorporate a docstring from the getter method. Improve readabilty with additional whitespace.
This commit is contained in:
parent
45059eb1d0
commit
97fc2ba6bf
1 changed files with 9 additions and 5 deletions
|
|
@ -1512,21 +1512,25 @@ PyDoc_STRVAR(property_doc,
|
||||||
"\n"
|
"\n"
|
||||||
"fget is a function to be used for getting an attribute value, and likewise\n"
|
"fget is a function to be used for getting an attribute value, and likewise\n"
|
||||||
"fset is a function for setting, and fdel a function for del'ing, an\n"
|
"fset is a function for setting, and fdel a function for del'ing, an\n"
|
||||||
"attribute. Typical use is to define a managed attribute x:\n"
|
"attribute. Typical use is to define a managed attribute x:\n\n"
|
||||||
"class C(object):\n"
|
"class C(object):\n"
|
||||||
" def getx(self): return self._x\n"
|
" def getx(self): return self._x\n"
|
||||||
" def setx(self, value): self._x = value\n"
|
" def setx(self, value): self._x = value\n"
|
||||||
" def delx(self): del self._x\n"
|
" def delx(self): del self._x\n"
|
||||||
" x = property(getx, setx, delx, \"I'm the 'x' property.\")\n"
|
" x = property(getx, setx, delx, \"I'm the 'x' property.\")\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Decorators make defining new properties or modifying existing ones easy:\n"
|
"Decorators make defining new properties or modifying existing ones easy:\n\n"
|
||||||
"class C(object):\n"
|
"class C(object):\n"
|
||||||
" @property\n"
|
" @property\n"
|
||||||
" def x(self): return self._x\n"
|
" def x(self):\n"
|
||||||
|
" \"\I am the 'x' property.\"\n"
|
||||||
|
" return self._x\n"
|
||||||
" @x.setter\n"
|
" @x.setter\n"
|
||||||
" def x(self, value): self._x = value\n"
|
" def x(self, value):\n"
|
||||||
|
" self._x = value\n"
|
||||||
" @x.deleter\n"
|
" @x.deleter\n"
|
||||||
" def x(self): del self._x\n"
|
" def x(self):\n"
|
||||||
|
" del self._x\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue