Skip to content

Commit 1751333

Browse files
Merge pull request RustPython#650 from chylli/add_str__doc__
add __doc__ to str
2 parents 9e5b76c + e38a82e commit 1751333

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

vm/src/obj/objstr.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,16 @@ impl IntoPyObject for String {
612612
#[rustfmt::skip] // to avoid line splitting
613613
pub fn init(context: &PyContext) {
614614
let str_type = &context.str_type;
615+
let str_doc = "str(object='') -> str\n\
616+
str(bytes_or_buffer[, encoding[, errors]]) -> str\n\
617+
\n\
618+
Create a new string object from the given object. If encoding or\n\
619+
errors is specified, then the object must expose a data buffer\n\
620+
that will be decoded using the given encoding and error handler.\n\
621+
Otherwise, returns the result of object.__str__() (if defined)\n\
622+
or repr(object).\n\
623+
encoding defaults to sys.getdefaultencoding().\n\
624+
errors defaults to 'strict'.";
615625
context.set_attr(&str_type, "__add__", context.new_rustfunc(PyStringRef::add));
616626
context.set_attr(&str_type, "__eq__", context.new_rustfunc(PyStringRef::eq));
617627
context.set_attr(&str_type, "__contains__", context.new_rustfunc(PyStringRef::contains));
@@ -666,6 +676,7 @@ pub fn init(context: &PyContext) {
666676
context.set_attr(&str_type, "center", context.new_rustfunc(PyStringRef::center));
667677
context.set_attr(&str_type, "expandtabs", context.new_rustfunc(PyStringRef::expandtabs));
668678
context.set_attr(&str_type, "isidentifier", context.new_rustfunc(PyStringRef::isidentifier));
679+
context.set_attr(&str_type, "__doc__", context.new_str(str_doc.to_string()));
669680
}
670681

671682
pub fn get_value(obj: &PyObjectRef) -> String {

0 commit comments

Comments
 (0)