Skip to content

Commit a6beeac

Browse files
committed
property type: Added __doc__
1 parent 07fd61f commit a6beeac

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

vm/src/obj/objproperty.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,35 @@ use super::objtype;
88

99
pub fn init(context: &PyContext) {
1010
let property_type = &context.property_type;
11+
12+
let property_doc =
13+
"Property attribute.\n\n \
14+
fget\n \
15+
function to be used for getting an attribute value\n \
16+
fset\n \
17+
function to be used for setting an attribute value\n \
18+
fdel\n \
19+
function to be used for del\'ing an attribute\n \
20+
doc\n \
21+
docstring\n\n\
22+
Typical use is to define a managed attribute x:\n\n\
23+
class C(object):\n \
24+
def getx(self): return self._x\n \
25+
def setx(self, value): self._x = value\n \
26+
def delx(self): del self._x\n \
27+
x = property(getx, setx, delx, \"I\'m the \'x\' property.\")\n\n\
28+
Decorators make defining new properties or modifying existing ones easy:\n\n\
29+
class C(object):\n \
30+
@property\n \
31+
def x(self):\n \"I am the \'x\' property.\"\n \
32+
return self._x\n \
33+
@x.setter\n \
34+
def x(self, value):\n \
35+
self._x = value\n \
36+
@x.deleter\n \
37+
def x(self):\n \
38+
del self._x";
39+
1140
context.set_attr(
1241
&property_type,
1342
"__get__",
@@ -18,6 +47,11 @@ pub fn init(context: &PyContext) {
1847
"__new__",
1948
context.new_rustfunc(property_new),
2049
);
50+
context.set_attr(
51+
&property_type,
52+
"__doc__",
53+
context.new_str(property_doc.to_string()),
54+
);
2155
// TODO: how to handle __set__ ?
2256
}
2357

0 commit comments

Comments
 (0)