Skip to content

add __doc__ to str #650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions vm/src/obj/objstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,16 @@ impl IntoPyObject for String {
#[rustfmt::skip] // to avoid line splitting
pub fn init(context: &PyContext) {
let str_type = &context.str_type;
let str_doc = "str(object='') -> str\n\
str(bytes_or_buffer[, encoding[, errors]]) -> str\n\
\n\
Create a new string object from the given object. If encoding or\n\
errors is specified, then the object must expose a data buffer\n\
that will be decoded using the given encoding and error handler.\n\
Otherwise, returns the result of object.__str__() (if defined)\n\
or repr(object).\n\
encoding defaults to sys.getdefaultencoding().\n\
errors defaults to 'strict'.";
context.set_attr(&str_type, "__add__", context.new_rustfunc(PyStringRef::add));
context.set_attr(&str_type, "__eq__", context.new_rustfunc(PyStringRef::eq));
context.set_attr(&str_type, "__contains__", context.new_rustfunc(PyStringRef::contains));
Expand Down Expand Up @@ -666,6 +676,7 @@ pub fn init(context: &PyContext) {
context.set_attr(&str_type, "center", context.new_rustfunc(PyStringRef::center));
context.set_attr(&str_type, "expandtabs", context.new_rustfunc(PyStringRef::expandtabs));
context.set_attr(&str_type, "isidentifier", context.new_rustfunc(PyStringRef::isidentifier));
context.set_attr(&str_type, "__doc__", context.new_str(str_doc.to_string()));
}

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