VersionInfo.parse should be a class method
See original GitHub issueI wanted to create a subclass of VersionInfo for company reasons (more checkings, more methods, etc) and it turned out the VersionInfo.parse is a staticmethod, always returning VersionInfo instances, no matter what.
By turning the parse
static method into a class method and making it return cls(**version_parts)
the result of parse will be an instance of the subclass (my class), not the superclass (VersionInfo).
e.g:
class MyBogusVersionInfo(semver.VersionInfo):
@classmethod
def parse(cls, version):
if version.startswith("foobar"):
version = version[6:]
return super().parse(version)
print(type(MyBogusVersionInfo.parse("1.2.3")))
Current result is : <class 'semver.VersionInfo'>
, while I would have expected <class 'MyBogusVersionInfo'>
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Using semver — python-semver 2.13.0 documentation
The semver module can store a version in the semver.VersionInfo class. For historical reasons, a version can be also stored as a string...
Read more >Consider keeping compare module level function #258 - GitHub
I would think that comparing two semver strings is a pretty common use case and this code: semver.compare("1.2.3", "3.2.1") is arguably a ...
Read more >Version.Parse Method (System) - Microsoft Learn
Converts the specified read-only span of characters that represents a version number to an equivalent Version object.
Read more >How do I compare version numbers in Python? - Stack Overflow
+\. egg$ to extract the name and version from the filename. The problem is comparing the version number, which is a string like...
Read more >Version (Spring Data Core 3.0.0 API)
Parses the given string representation of a version into a Version object. String. toString(). Methods inherited from class java.lang.Object.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m glade it makes sense. On my part, there is no requirement nor need for a python2 compatibility. My team and I are working with python >= 3.6. Thank you for your work !
I can provide tests and examples if it’s accepted, though. Feel free to ask.