Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/usage/increase-parts-of-a-version_prereleases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ would perhaps a better fit.
>>> str(Version.parse("3.4.5-pre.2+build.4").next_version(part="patch"))
'3.4.5'
>>> str(Version.parse("3.4.5+build.4").next_version(part="patch"))
'3.4.5'
'3.4.6'
>>> str(Version.parse("0.1.4").next_version("prerelease"))
'0.1.5-rc.1'
2 changes: 1 addition & 1 deletion src/semver/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def next_version(self, part: str, prerelease_token: str = "rc") -> "Version":
f"Invalid part. Expected one of {validparts}, but got {part!r}"
)
version = self
if (version.prerelease or version.build) and (
if version.prerelease and (
part == "patch"
or (part == "minor" and version.patch == 0)
or (part == "major" and version.minor == version.patch == 0)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ def test_next_version_with_invalid_parts():
("0.2.0-rc.1", "patch", "0.2.0"), # same as "minor"
("1.0.0-rc.1", "patch", "1.0.0"), # same as "major"
("1.0.0-rc.1", "minor", "1.0.0"), # same as "major"
# build-only versions: build metadata does not affect precedence,
# so next_version should bump the version, not just strip the build
("1.2.3+build.5", "patch", "1.2.4"),
("1.0.0+build.5", "patch", "1.0.1"),
("0.1.4+build.5", "patch", "0.1.5"),
("1.2.0+build.5", "minor", "1.3.0"),
("1.0.0+build.5", "major", "2.0.0"),
# prerelease+build: build is stripped along with prerelease during finalization
("1.2.3-rc.1+build.5", "patch", "1.2.3"),
("1.2.3-rc.1+build.5", "prerelease", "1.2.3-rc.2"),
],
)
def test_next_version_with_versioninfo(version, part, expected):
Expand Down
Loading