Skip to content

Commit f55559a

Browse files
tlaferriereThomas Laferriere
andauthored
Fix #251: Correct return type for next_version() (#254)
* Return VersionInfo instance in VersionInfo.next_version and not str when part is major, minor, or patch. * Change test_next_version_with_versioninfo Test for correct return type (should be VersionInfo) * Update CHANGELOG.rst Co-authored-by: Thomas Laferriere <thomas.laferriere@bell.ca>
1 parent cf18005 commit f55559a

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

CHANGELOG.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,32 @@ Change Log
66
All notable changes to this code base will be documented in this file,
77
in every released version.
88

9+
Version 2.10.1 (WIP)
10+
====================
11+
12+
:Released: 2020-0x-0y
13+
:Maintainer:
14+
15+
16+
Features
17+
--------
18+
19+
20+
Bug Fixes
21+
---------
22+
23+
* :gh:`251` (:pr:`254`): Fixed return type of ``semver.VersionInfo.next_version``
24+
to always return a ``VersionInfo`` instance.
25+
26+
27+
Additions
28+
---------
29+
30+
31+
Removals
32+
--------
33+
34+
935
Version 2.10.0
1036
==============
1137

semver.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,8 @@ def next_version(self, part, prerelease_token="rc"):
471471
472472
:param part: One of "major", "minor", "patch", or "prerelease"
473473
:param prerelease_token: prefix string of prerelease, defaults to 'rc'
474-
:return:
474+
:return: new object with the appropriate part raised
475+
:rtype: :class:`VersionInfo`
475476
"""
476477
validparts = {
477478
"major",
@@ -495,7 +496,7 @@ def next_version(self, part, prerelease_token="rc"):
495496
return version.replace(prerelease=None, build=None)
496497

497498
if part in ("major", "minor", "patch"):
498-
return str(getattr(version, "bump_" + part)())
499+
return getattr(version, "bump_" + part)()
499500

500501
if not version.prerelease:
501502
version = version.bump_patch()

test_semver.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,4 +1050,6 @@ def test_next_version_with_invalid_parts():
10501050
)
10511051
def test_next_version_with_versioninfo(version, part, expected):
10521052
ver = VersionInfo.parse(version)
1053-
assert str(ver.next_version(part)) == expected
1053+
next_version = ver.next_version(part)
1054+
assert isinstance(next_version, VersionInfo)
1055+
assert str(next_version) == expected

0 commit comments

Comments
 (0)