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

Replace method not compatible with SubClasses #426

Copy link
Copy link
Closed
@dannystaple

Description

@dannystaple
Issue body actions

Situation

Using the demonstration subclass from https://python-semver.readthedocs.io/en/latest/advanced/create-subclasses-from-version.html#creating-subclasses-from-version, the bump methods will create a new instance of the same SubClass.

When using the replace method, an instance of the Version class is created and not the subclass.

To Reproduce

  1. Create a subclass as shown in the document above.
  2. version = SemVerWithVPrefix.parse("v1.1.0")
  3. dev_version = version.replace(prerelease="dev.0")
  4. Print str(dev_version)
  5. This results in 1.1.0-dev.0 - dev_version is of type Version not SemVerWithVPrefix.

Expected Behavior

I expect v1.1.0-dev.0 and dev_version to be an instance of SemVerWithVPrefix (or my class).

Environment

  • OS: [e.g. Linux, MacOS, Windows, ...] - Python 3.11 container - will be Debian.
  • Python version [e.g. 3.6, 3.7, ...] - Python 3.11.5
  • Version of semver library [e.g. 3.0.0] - semver==3.0.1

Additional context

I suggest changing this the same way that the bump methods work:
Add this near the top: cls = type(self)
And near the bottom, replace return Version(**version) with return cls(**version).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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.