[Feature Request] Implement __repr__
for all the major types in the stdlib
#2458
Labels
enhancement
New feature or request
good first issue
Good for newcomers
mojo-repo
Tag all issues with this label
mojo-stdlib
Tag for issues related to standard library
Review Mojo's priorities
What is your request?
This issue is a follow up on #2207 and #2361 .
We now have a
Representable
trait and more of our types in the mojo stdlib should have this trait. For some types likeList
orDict
it's not possible to add the trait but it's still possible to have a__repr__
static method. You can take a look at how__str__
is implemented there.If you are unsure about what the representation of a struct should look like, you can use these two guidelines:
repr()
does in Python for a similar object__str__
. Long story short, the output of__repr__
should be an unambiguous string that is a valid Mojo expression (you should be able to copy-paste it into a Mojo file to re-create the object).What is your motivation for this change?
__repr__
is useful for many things. One is debugging, the other is to be able to implement__str__
for containers. Long term, the debugger will callrepr(my_object_to_inspect)
andassert_equal()
will call therepr()
function when creating the error message.Any other details?
No response
The text was updated successfully, but these errors were encountered: