Skip to content

Commit 1c07a22

Browse files
Merge pull request RustPython#268 from mrecachinas/add-bool-doc
Add bool.__doc__ (addresses RustPython#260)
2 parents 2b22cd4 + 804def1 commit 1c07a22

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

tests/snippets/bools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def __bool__(self):
4040
assert not (False and fake)
4141
assert (True and 5) == 5
4242

43+
assert bool.__doc__ == "bool(x) -> bool\n\nReturns True when the argument x is true, False otherwise.\nThe builtins True and False are the only two instances of the class bool.\nThe class bool is a subclass of the class int, and cannot be subclassed."
44+
4345
# Bools are also ints.
4446
assert isinstance(True, int)
4547
assert True + True == 2

vm/src/obj/objbool.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,15 @@ pub fn boolval(vm: &mut VirtualMachine, obj: PyObjectRef) -> Result<bool, PyObje
3131

3232
pub fn init(context: &PyContext) {
3333
let ref bool_type = context.bool_type;
34+
let bool_doc = "bool(x) -> bool
35+
36+
Returns True when the argument x is true, False otherwise.
37+
The builtins True and False are the only two instances of the class bool.
38+
The class bool is a subclass of the class int, and cannot be subclassed.";
39+
3440
context.set_attr(&bool_type, "__new__", context.new_rustfunc(bool_new));
3541
context.set_attr(&bool_type, "__repr__", context.new_rustfunc(bool_repr));
42+
context.set_attr(&bool_type, "__doc__", context.new_str(bool_doc.to_string()));
3643
}
3744

3845
pub fn not(vm: &mut VirtualMachine, obj: &PyObjectRef) -> PyResult {

0 commit comments

Comments
 (0)