Thanks to visit codestin.com
Credit goes to github.com

Skip to content

VersionInfo.parse should be a class method #276

Closed
@Anvil

Description

@Anvil

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 ATMEnhancementNot a bug, but increases or improves in value, quality, desirability, or attractivenessQuestionUnclear 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