question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VersionInfo.parse should be a class method

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Anvilcommented, Oct 16, 2020

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 !

1reaction
Anvilcommented, Jul 24, 2020

I can provide tests and examples if it’s accepted, though. Feel free to ask.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found