mojo
mojo copied to clipboard
[mojo-stdlib] Replace uses of `<foo>.__str__()` with `str(foo)`
Review Mojo's priorities
- [X] I have read the roadmap and priorities and I believe this request falls within the priorities.
What is your request?
There are still instances in the standard library that call dunder str
function directly. As of several Mojo versions ago, we introduced the str(...)
function. So, we can safely replace foo.__str__()
with str(foo)
everywhere.
What is your motivation for this change?
Small refactoring for consistency/brevity.
Any other details?
Some examples:
stdlib/src/builtin/error.mojo: return self.__str__()
stdlib/src/pathlib/path.mojo: return self.__str__() == other.__str__()
stdlib/test/python/test_ownership.mojo: var py_string = my_list.__str__()
stdlib/test/python/test_ownership.mojo: var py_string = my_tuple.__str__()
stdlib/test/python/test_ownership.mojo: var py_string = obj.__str__()
stdlib/test/python/test_ownership.mojo: var py_string = obj[1].__str__()
stdlib/test/python/test_ownership.mojo: var py_string = obj.bar.__str__()
stdlib/test/python/test_python_to_mojo.mojo: var cap_mojo_string = py_string_capitalized.__str__()
@JoeLoser I believe this issue is fixed.
Fixed with https://github.com/modularml/mojo/commit/6dcfba129c433cbc7d85b775e173edc14e0b7f14, thank you!