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

Fix vText.__repr__ BytesWarning #554

Merged
merged 1 commit into from
Sep 17, 2023
Merged

Fix vText.__repr__ BytesWarning #554

merged 1 commit into from
Sep 17, 2023

Conversation

scop
Copy link
Contributor

@scop scop commented Sep 17, 2023

Exposed by running in python3 -b mode.

@@ -719,7 +719,7 @@ def __new__(cls, value, encoding=DEFAULT_ENCODING):
return self

def __repr__(self):
return f"vText('{self.to_ical()}')"
return f"vText('{self.to_ical()!r}')"
Copy link
Contributor Author

@scop scop Sep 17, 2023

Choose a reason for hiding this comment

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

The !r approach preserves existing behavior. Depending on desired outcome, another fix would be

Suggested change
return f"vText('{self.to_ical()!r}')"
return f"vText('{self.to_ical().decode(self.encoding)}')"

Copy link
Collaborator

Choose a reason for hiding this comment

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

I like the decode version better

@jacadzaca
Copy link
Collaborator

hey, big thanks for the PR! Since the ical text is stored as bytes internally, I think having bytes explicitly in __repr__ is correct behavior. However, I think your suggestion would be an ideal implementation of an __str__ :) What do you think?

A __str__ / __repr__ implementation for other v elements would also be very welcome, since they all are lacking one :)

Also, please fill out the CHANGELOG and add yourself to CREDITS as per CONTRIBUTING

Exposed by running in `python3 -b` mode.
@scop
Copy link
Contributor Author

scop commented Sep 17, 2023

Since the ical text is stored as bytes internally, I think having bytes explicitly in __repr__ is correct behavior.

Agree, that's (and for no behavioral changes) why I opted for the !r option.

However, I think your suggestion would be an ideal implementation of an __str__ :) What do you think?

Kind of, but then again I don't know if the vText('...') "wrapper" belongs in it. Anyway, I'd like to leave that and addition of any additional __str__/__repr__ implementations out from this PR to keep it in scope. And frankly, leave all that to someone else to take care of :)

Also, please fill out the CHANGELOG and add yourself to CREDITS

Done.

@jacadzaca jacadzaca merged commit 52d5cea into collective:master Sep 17, 2023
9 checks passed
@jacadzaca
Copy link
Collaborator

Thanks for the PR :)

@scop scop deleted the patch-1 branch September 17, 2023 08:47
@niccokunzmann
Copy link
Member

This is part of release 5.0.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants