Bump version inside VersionInfo directly
See original GitHub issueSituation
Hope I don’t miss anything, but reading the source code didn’t give a solution. It seems to me, dealing with version numbers and raising parts of it can actually quite tricky.
For example, let’s assume you’ve created a version like this:
ver = semver.parse_version_info("3.4.5")
How can you raise the major part? How the minor part? The ver
variable is of type VersionInfo
. You can’t directly use semver.bump_major
or semver.bump_minor
as they accept strings only. Nor does the class provide any methods. However, you could do something like that:
semver.bump_major(str(ver))
This works, but your VersionInfo
type is converted into a string. Not good if you want to keep the type. If you want it back, you need to write:
semver.parse_version_info(semver.bump_major(str(ver)))
Not very pythonic. 😉
Possible Solution(s)
From what I can see, we have a good class, but we can’t raise parts individually. I think, this is gap. I could think of these solutions:
- Allow
semver.bump_major
and the other bump functions allow aVersionInfo
type. - Extend the
VersionInfo
class with additional methods likeinc_major()
,inc_minor()
etc. - Something else?
At the moment, I think number 2 can be a possible solution. Theoretically, you could name them also bump_major
, but that could confuse people.
The above could be rewritten like that:
ver.inc_major()
If we go with this, there are two possible ways how this function could work:
- Return the raised version of
ver
but leavever
itself untouched. - Return nothing (=None) and raise the part directly in
ver
.
Solution 1 could be interesting as it would allow to write something like this:
new_ver = ver.inc_major().inc_minor()
What do you think?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
@tomschr it’s an interesting use case - I’ve never thought about it. I think, from user point of view, better approach is to use regular method and return updated object (as you suggested) and forget about class method 😃
Uups, this was already fixed in commit a598059, but wasn’t closed automatically.