Repository navigation
Decode bytes prerelease and build parts in Version - #536
Open
kevincommits wants to merge 1 commit into
Open
kevincommits wants to merge 1 commit into
kevincommits wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
Versionconstructor annotatesprereleaseandbuildasOptional[Union[String, int]], whereStringisUnion[str, bytes], andmajor,minorandpatchalready accept bytes. But bytes passed asprereleaseorbuildgo throughstr(), which stores their repr:Expected
'1.2.3-rc.1+build.4', the same result asVersion.parse(b"1.2.3-rc.1+build.4"). The current string is not valid SemVer, cannot be parsed back, and the version compares unequal to the parsed one.The constructor now decodes bytes
prereleaseandbuildvalues as UTF-8, the same wayVersion.parse()decodes bytes input. Other types are converted withstr()as before.The new test in
tests/test_semver.pybuilds a version from bytes parts and checks both properties andstr(). A towncrier fragment is included.An alternative would be to drop
bytesfrom the annotation and reject it; I went with decoding becauseparse()and the numeric parts already accept bytes. #317 reworks__init__and would also cover this if it lands; this is a small fix that does not depend on it.What I ran:
pytest(600 passed, 1 skipped, 100% coverage) on Python 3.13;ruff check,mypy srcanddocformatter --check srcreport the same findings before and after this change;towncrier build --draft.What I did not run: the other Python versions in the tox matrix.