Skip to content

fix: next_version should bump version for build-only versions - #469

Merged
tomschr merged 2 commits into
python-semver:masterfrom
gaoflow:fix-next-version-build
Jul 15, 2026
Merged

fix: next_version should bump version for build-only versions#469
tomschr merged 2 commits into
python-semver:masterfrom
gaoflow:fix-next-version-build

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Fixes a bug where next_version on versions with build metadata but no prerelease would strip the build without bumping the version.

Bug

Version.parse('1.2.3+build.5').next_version('patch') returns 1.2.3 instead of 1.2.4.

The condition in next_version was (version.prerelease or version.build), which caused build-only versions to enter the finalization path meant for prereleases. Build metadata does not affect semver precedence, so its presence should not trigger version finalization -- the version should be bumped.

Same issue affects next_version('minor') on X.Y.0+build and next_version('major') on X.0.0+build.

Fix

Change the condition from version.prerelease or version.build to version.prerelease. Prerelease+build versions still correctly finalize (stripping both prerelease and build).

Checklist

  • One-line fix in version.py
  • 7 new test cases covering build-only and prerelease+build scenarios
  • All 340 existing+tests pass (100% coverage)

@tomschr

tomschr commented Jun 29, 2026

Copy link
Copy Markdown
Member

Thank you @gaoflow for your contribution! 🎉

Could you rebase your branch to the latest master branch? I've fixed the CI problem and raised semver to version 3.1.0.

Thank you!

@tomschr tomschr added the Bug Error, flaw or fault to produce incorrect or unexpected results label Jun 29, 2026
next_version('patch') on a version with build metadata but no prerelease
(e.g. 1.2.3+build.5) would strip the build and return the same version
(1.2.3) instead of bumping the patch (1.2.4).

The condition in next_version was (version.prerelease or version.build),
which caused build-only versions to enter the 'finalization' path meant
for prereleases. Build metadata does not affect version precedence, so
its presence should not trigger version finalization.

Change the condition to only check version.prerelease.
@gaoflow
gaoflow force-pushed the fix-next-version-build branch from a3cd2f7 to 6cb1cae Compare June 29, 2026 16:06
@gaoflow

gaoflow commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Done — rebased onto the latest master (3.1.0). Thanks for sorting out the CI!

@tomschr

tomschr commented Jun 29, 2026

Copy link
Copy Markdown
Member

@gaoflow Thank you for your help! 👍 The CI reports one failed doctest in docs/usage/increase-parts-of-a-version_prereleases.rst. Can you fixed that, please? 😃 Thanks!

@tomschr
tomschr merged commit 4e09ef0 into python-semver:master Jul 15, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Error, flaw or fault to produce incorrect or unexpected results

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants