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

[stdlib] add __str__ and __repr__ for Optional #3061

Open
wants to merge 1 commit into
base: nightly
Choose a base branch
from

Conversation

bgreni
Copy link
Contributor

@bgreni bgreni commented Jun 16, 2024

Add format_to __str__ and __repr__

@bgreni bgreni requested a review from a team as a code owner June 16, 2024 05:50
@bgreni bgreni changed the title [stdlib] add str and repr for Optional [stdlib] add __str__ and __repr__ for Optional Jun 16, 2024
Copy link
Contributor

@gabrieldemarmiesse gabrieldemarmiesse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition. I think we can be more efficient here by skipping a temporary allocation of a possibly big string.

writer: The formatter to write to.
"""
if self:
write_to(writer, repr(self.value()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here repr(self.value()) can be a very big String. If we know that self.value() has a format_to method, would it be possible to use it to write directly to the Formatter?

You can imagine that self.value() is a List with 10 000 elements for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea, but wouldn't that require use to generally shift away from RepresentableCollectionElement in these scenarios to something equivalent to Formattable & CollectionElement?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Gabriel that we could make this more efficient, though we can do that in a follow-up PR if you'd like 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well do it here. I'm on vacation at the moment but I can look into it on Monday!

@ConnorGray
Copy link
Collaborator

!sync

@ConnorGray
Copy link
Collaborator

It looks like I can't sync this because of the merge conflict. @bgreni could you rebase and then I'll merge this? Thanks! 🙂

@ConnorGray ConnorGray added the waiting for response Needs action/response from contributor before a PR can proceed label Jun 24, 2024
@bgreni
Copy link
Contributor Author

bgreni commented Jun 27, 2024

It looks like I can't sync this because of the merge conflict. @bgreni could you rebase and then I'll merge this? Thanks! 🙂

Done now, apologies for the delay!

@ConnorGray
Copy link
Collaborator

Done now, apologies for the delay!

No worries at all, thank you for fixing the conflict! I'll sync this in now.

@ConnorGray
Copy link
Collaborator

!sync

@ConnorGray ConnorGray removed the waiting for response Needs action/response from contributor before a PR can proceed label Jun 27, 2024
@modularbot modularbot added the imported-internally Signals that a given pull request has been imported internally. label Jun 27, 2024
Signed-off-by: Brian Grenier <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
imported-internally Signals that a given pull request has been imported internally.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants