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

Refactor canonicalize_version #793

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jaraco
Copy link
Member

@jaraco jaraco commented Apr 13, 2024

In reviewing the behavior of canonicalize_version, I found the documentation and implementation to be somewhat lacking in context. The docstring alluded to a difference but didn't indicate what the difference was exactly. By comparing it with Version.__str__, one could see that the bulk of the function was a copy/paste, but there was one bit accounting for the altered release behavior. This approach now shares the same implementation of the Version.__str__ and also takes advantage of singledispatch to separate the two forms for better separation. It also takes the opportunity to document the behaviors more fully.

  • In canonicalize_version, re-use Version.str.
  • Utilize singledispatch to separate concerns in canonicalize_version.

>>> canonicalize_version('foo bar baz')
'foo bar baz'
"""
return str(_TrimmedRelease(str(version)) if strip_trailing_zero else version)
Copy link
Member Author

Choose a reason for hiding this comment

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

This code would be simpler and more intuitive if Version had a copy constructor, but since it doesn't, casting to str to construct the _TrimmedRelease works nicely.

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.

None yet

1 participant