mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[mojo-stdlib] Replace uses of `<foo>.__str__()` with `str(foo)`

Open JoeLoser opened this issue 10 months ago • 1 comments

Review Mojo's 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 avatar Mar 28 '24 19:03 JoeLoser

@JoeLoser I believe this issue is fixed.

Shaikh-Ubaid avatar Mar 29 '24 00:03 Shaikh-Ubaid

Fixed with https://github.com/modularml/mojo/commit/6dcfba129c433cbc7d85b775e173edc14e0b7f14, thank you!

JoeLoser avatar Apr 03 '24 20:04 JoeLoser