Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

VersionInfo.parse should be a class method #276

Copy link
Copy link
Closed
@Anvil

Description

@Anvil
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BlockedIssue depends on a different issue or cannot be solved ATMIssue depends on a different issue or cannot be solved ATMEnhancementNot a bug, but increases or improves in value, quality, desirability, or attractivenessNot a bug, but increases or improves in value, quality, desirability, or attractivenessQuestionUnclear or open issue subject for debateUnclear or open issue subject for debate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.