Skip to content
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

[Feature Request] Implement __repr__ for all the major types in the stdlib #2458

Open
1 task done
gabrieldemarmiesse opened this issue May 1, 2024 · 2 comments
Open
1 task done
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

Comments

@gabrieldemarmiesse
Copy link
Contributor

gabrieldemarmiesse commented May 1, 2024

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 like List or Dict 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:

  • Take a look at what repr() does in Python for a similar object
  • Take a look at the python docs explaining the difference with __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 call repr(my_object_to_inspect) and assert_equal() will call the repr() function when creating the error message.

Any other details?

No response

@gabrieldemarmiesse gabrieldemarmiesse added enhancement New feature or request mojo-repo Tag all issues with this label labels May 1, 2024
@JoeLoser JoeLoser added good first issue Good for newcomers mojo-stdlib Tag for issues related to standard library labels May 1, 2024
@ematejska ematejska removed the mojo-stdlib Tag for issues related to standard library label May 1, 2024
@whym1here
Copy link

Can I work on this issue?

@gabrieldemarmiesse
Copy link
Contributor Author

Sure thing, you don't need to ask :)

@ematejska ematejska added the mojo-stdlib Tag for issues related to standard library label May 3, 2024 — with Linear
@ematejska ematejska removed the mojo-stdlib Tag for issues related to standard library label May 6, 2024
@ematejska ematejska added the mojo-stdlib Tag for issues related to standard library label May 6, 2024 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

4 participants