Skip to content

Commit c24a88c

Browse files
Merge pull request RustPython#369 from ZapAnton/bytes_doc
bytes type: Added __doc__
2 parents 4d02a1e + 1992e02 commit c24a88c

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

vm/src/obj/objbytes.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,29 @@ use std::ops::Deref;
1414
// Fill bytes class methods:
1515
pub fn init(context: &PyContext) {
1616
let bytes_type = &context.bytes_type;
17+
18+
let bytes_doc =
19+
"bytes(iterable_of_ints) -> bytes\n\
20+
bytes(string, encoding[, errors]) -> bytes\n\
21+
bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer\n\
22+
bytes(int) -> bytes object of size given by the parameter initialized with null bytes\n\
23+
bytes() -> empty bytes object\n\nConstruct an immutable array of bytes from:\n \
24+
- an iterable yielding integers in range(256)\n \
25+
- a text string encoded using the specified encoding\n \
26+
- any object implementing the buffer API.\n \
27+
- an integer";
28+
1729
context.set_attr(bytes_type, "__eq__", context.new_rustfunc(bytes_eq));
1830
context.set_attr(bytes_type, "__hash__", context.new_rustfunc(bytes_hash));
1931
context.set_attr(bytes_type, "__new__", context.new_rustfunc(bytes_new));
2032
context.set_attr(bytes_type, "__repr__", context.new_rustfunc(bytes_repr));
2133
context.set_attr(bytes_type, "__len__", context.new_rustfunc(bytes_len));
22-
context.set_attr(bytes_type, "__iter__", context.new_rustfunc(bytes_iter))
34+
context.set_attr(bytes_type, "__iter__", context.new_rustfunc(bytes_iter));
35+
context.set_attr(
36+
bytes_type,
37+
"__doc__",
38+
context.new_str(bytes_doc.to_string()),
39+
);
2340
}
2441

2542
fn bytes_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {

0 commit comments

Comments
 (0)