Skip to content

Annotate supported bytes inputs to Version.is_valid - #495

Merged
tomschr merged 3 commits into
python-semver:masterfrom
xiehuanyi:fix-bytes-input-annotations
Oct 18, 2026
Merged

tomschr merged 3 commits into
python-semver:masterfrom
xiehuanyi:fix-bytes-input-annotations

Conversation

@xiehuanyi

Copy link
Copy Markdown
Contributor

Version.is_valid() already accepts UTF-8 encoded bytes through Version.parse(), but its str annotation makes type checkers reject those valid calls. Use the existing String alias and clarify the parameter documentation.

Validation: the same bytes examples run on the original implementation; mypy rejects two calls before and accepts them afterward, and Pyright passes. The existing suite passes 488 tests, with one optional-native-backend skip and 100% statement/branch coverage. The repository's 160 Ruff diagnostics and one source-mypy error for the absent optional backend are identical on clean upstream and this patch.

Prepared and verified with Codex (GPT-6.1-sol) assistance.

Copilot AI balanced review requested due to automatic review settings October 11, 2026 18:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@xiehuanyi
xiehuanyi force-pushed the fix-bytes-input-annotations branch from c0b47fd to 9a06b7c Compare October 11, 2026 18:32

@tomschr tomschr left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @xiehuanyi for your contribution, much appreciated! 👍

It looks fine. The only change I'd suggest is a small test case that address the byte string case. Something like this:

def test_is_valid_accepts_bytes():
    assert Version.is_valid(b"1.0.0") is True
    assert Version.is_valid(b"foo") is False
    assert Version.is_valid("1.0.0".encode("UTF-8")) is True

The first two lines cover the valid and invalid cases. The third is optional, but it makes the UTF-8 wording in the docstring explicit.

A bytes case that isn't valid UTF-8 would also be worth a look, since parse() calls .decode("UTF-8"), which raises UnicodeDecodeError, not ValueError. Then is_valid() would propagate the exception instead of returning False. That's existing behavior, but it's relevant to what the docstring promises, so I'd check it before merging.

Could you add that please? Thanks!

@xiehuanyi xiehuanyi closed this Oct 12, 2026
@xiehuanyi

Copy link
Copy Markdown
Contributor Author

@tomschr Thanks for the review. The requested byte-string tests are in 40b14bf, covering valid bytes, invalid version bytes, UTF-8 encoded input, and invalid UTF-8. UnicodeDecodeError is a subclass of ValueError, so the existing handler already returns False for b"\xff"; the new test covers that. The local suite passed with 492 tests passed and 1 skipped.

I closed the PR because I reached my repair time limit before completing remote verification and the PR description update. I should have explained the closure at the time.

@tomschr tomschr reopened this Oct 15, 2026
@tomschr

tomschr commented Oct 15, 2026

Copy link
Copy Markdown
Member

Thank you @xiehuanyi for the answers and the additional commit. They look fine. I just have this minor thing. I'll merge it once the minor thing is fixed.

Again, thanks for your contribution! 🎉 ❤️

@xiehuanyi xiehuanyi closed this Oct 16, 2026
@tomschr tomschr reopened this Oct 16, 2026
@xiehuanyi

Copy link
Copy Markdown
Contributor Author

@tomschr Thanks for reopening this. The byte-string regression tests are already in 40b14bf, and the current CI checks are green. I can see your message about a remaining minor change, but no submitted inline comment describing it. Could you point me to the change you have in mind?

I will leave the PR open for your review. As noted earlier, I have reached the repair-time limit for this contribution, so I cannot make additional edits under the current workflow; the existing patch remains available for you to adjust if useful.

@tomschr

tomschr commented Oct 18, 2026

Copy link
Copy Markdown
Member

I can see your message about a remaining minor change, but no submitted inline comment describing it. Could you point me to the change you have in mind?

I already changed it. It was just a minor fix from _UTF8_VERSION" to UTF8_VERSION`. Nothing spectacular. 😉

That fixes all remaining issues and it's ready to be merged.

Comment thread tests/test_semver.py Outdated
Comment thread tests/test_semver.py Outdated
@tomschr
tomschr merged commit 94debf9 into python-semver:master Oct 18, 2026
17 checks passed
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