Visitar URL original
fix: next_version should bump version for build-only versions · python-semver/python-semver@6cb1cae · GitHub
Skip to content

Commit 6cb1cae

Browse files
committed
fix: next_version should bump version for build-only versions
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.
1 parent 9c19156 commit 6cb1cae

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎src/semver/version.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def next_version(self, part: str, prerelease_token: str = "rc") -> "Version":
471471
f"Invalid part. Expected one of {validparts}, but got {part!r}"
472472
)
473473
version = self
474-
if (version.prerelease or version.build) and (
474+
if version.prerelease and (
475475
part == "patch"
476476
or (part == "minor" and version.patch == 0)
477477
or (part == "major" and version.minor == version.patch == 0)

‎tests/test_parsing.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@ def test_next_version_with_invalid_parts():
198198
("0.2.0-rc.1", "patch", "0.2.0"), # same as "minor"
199199
("1.0.0-rc.1", "patch", "1.0.0"), # same as "major"
200200
("1.0.0-rc.1", "minor", "1.0.0"), # same as "major"
201+
# build-only versions: build metadata does not affect precedence,
202+
# so next_version should bump the version, not just strip the build
203+
("1.2.3+build.5", "patch", "1.2.4"),
204+
("1.0.0+build.5", "patch", "1.0.1"),
205+
("0.1.4+build.5", "patch", "0.1.5"),
206+
("1.2.0+build.5", "minor", "1.3.0"),
207+
("1.0.0+build.5", "major", "2.0.0"),
208+
# prerelease+build: build is stripped along with prerelease during finalization
209+
("1.2.3-rc.1+build.5", "patch", "1.2.3"),
210+
("1.2.3-rc.1+build.5", "prerelease", "1.2.3-rc.2"),
201211
],
202212
)
203213
def test_next_version_with_versioninfo(version, part, expected):

0 commit comments

Comments
 (0)