Skip to content

Add missing methods to str class. #190

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

Closed
windelbouwman opened this issue Nov 7, 2018 · 13 comments
Closed

Add missing methods to str class. #190

windelbouwman opened this issue Nov 7, 2018 · 13 comments
Labels
good first issue Good for newcomers

Comments

@windelbouwman
Copy link
Contributor

The str class is still missing several methods. In CPython there exist a lot of handy methods you can use on strings. To fix this issue, head over to the file vm/src/obj/objstr.rs and add a method you found was missing.

This is a good first issue. If you completed your mission, please create another good starter issue for others to get their hands dirty with the sourcecode!

@windelbouwman windelbouwman added E-help-wanted Extra attention is needed good first issue Good for newcomers and removed E-help-wanted Extra attention is needed labels Nov 7, 2018
@mcon
Copy link
Contributor

mcon commented Feb 2, 2019

Looks like string_expected_methods includes everything that dir('foobar') contains in cpython, and objstr.rs has an implementation of each of those - think this ticket can be closed.

@ZapAnton
Copy link
Contributor

ZapAnton commented Feb 2, 2019

I would disagree.

isdecimal is not implemented
maketrans is also not implemented

@mcon
Copy link
Contributor

mcon commented Feb 3, 2019

My mistake, you're correct - misinterpreted whats_left_to_implement - looks like the following all need doing:

string . __dir__
string . __doc__
string . __format__
string . __ge__
string . __getnewargs__
string . __init_subclass__
string . __iter__
string . __le__
string . __mod__
string . __reduce__
string . __reduce_ex__
string . __rmod__
string . __rmul__
string . __setattr__
string . __sizeof__
string . __subclasshook__
string . encode
string . format_map
string . isdecimal
string . isprintable
string . maketrans
string . translate

@epellis
Copy link

epellis commented Mar 12, 2019

Looks like the following (maybe more) have already been implemented:

string . isdecimal
string . __ge__
string . __doc__
string . __format__

@yanganto
Copy link
Contributor

yanganto commented Jun 9, 2019

implement str.isprintable #1024

@bytesnail
Copy link

@windelbouwman What other work remains waiting for completion and implementation under this question? I am happy to contribute my spare time to this issue.

@windelbouwman
Copy link
Contributor Author

@longwusha did you run the what is left script to check missing methods on the str type?

@bytesnail
Copy link

bytesnail commented Jul 23, 2019

@windelbouwman

When I ran the what is left script, I got these missing methods on the str type:

str.__getnewargs__
str.__init_subclass__
str.__iter__
str.__rmod__
str.__sizeof__
str.__subclasshook__
str.format_map

I am not sure are there any other people working on these.

@bytesnail
Copy link

@windelbouwman

As we can see, some one was trying to implement str.iter in #593 . But it seems that he has no interest or time to continue this work, so I want to start to implement other missing methods on the str type based on his work.

It seems that since his last commit (four months ago) the code has undergone a lot of changes, I hope that you can provide some suggestions to help me get started. I will be very grateful for your suggestion.

@windelbouwman
Copy link
Contributor Author

windelbouwman commented Jul 23, 2019

@longwusha I think string iteration already works, at least I can use x = iter("fu"). You might want to try and import a module you would like to use, and see what problem you hit. That's at least a good way to start working on something.

If you like you can pickup the work from #593, since this work was abandoned. Adding a method to an object is a very good way to get yourself up and running with the codebase. Make sure to create a test snippet in the tests/snippets directory for the function you add. When you have created something, you can create a pull request, then we can review what you did.

Also, str.format_map might be a nice challenge to work on. We already have string formatting functions in cformat.rs and format.rs which you could probably re-use.

@windelbouwman
Copy link
Contributor Author

Another method which might be a good starter is the int.__rdivmod__ method. Try to create some testcases for this, and then implement the method.

@bytesnail
Copy link

Thank you very much for your good advice, I will try to start with str.format_map.

windelbouwman pushed a commit that referenced this issue Aug 16, 2019
* Add str.__rmod__ method.

* Add tests for str.__rmod__ method.

* Improve test for str.__rmod__ method.

* Change str.__rmod__ method return value type.

* Format with rustfmt.

* Remove not required code of str.__rmod__ method.

* Improve with clippy.
@youknowone
Copy link
Member

youknowone commented Jan 2, 2020

str class is now practically done. See #1346 for __init_subclass__. __getnewargs__ maybe better to be coverd in pickle issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

7 participants