-
Notifications
You must be signed in to change notification settings - Fork 96
Closed
Description
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
- Create a subclass as shown in the document above.
version = SemVerWithVPrefix.parse("v1.1.0")dev_version = version.replace(prerelease="dev.0")- Print
str(dev_version) - This results in
1.1.0-dev.0- dev_version is of typeVersionnotSemVerWithVPrefix.
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).
tomschr
Metadata
Metadata
Assignees
Labels
No labels