Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/semver/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _comparator(operator: Comparator) -> Comparator:
@wraps(operator)
def wrapper(self: "Version", other: Comparable) -> bool:
comparable_types = (
Version,
type(self),
dict,
tuple,
list,
Expand Down
18 changes: 18 additions & 0 deletions tests/test_subclass.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from semver import Version
import pytest


def test_subclass_from_versioninfo():
Expand Down Expand Up @@ -51,3 +52,20 @@ def __str__(self) -> str:
dev_version = version.replace(prerelease="dev.0")

assert str(dev_version) == "v1.1.0-dev.0"


def test_compare_with_subclass():
class SemVerSubclass(Version):
pass

with pytest.raises(TypeError):
SemVerSubclass.parse("1.0.0").compare(Version.parse("1.0.0"))
assert Version.parse("1.0.0").compare(SemVerSubclass.parse("1.0.0")) == 0

assert (
SemVerSubclass.parse("1.0.0").__eq__(Version.parse("1.0.0")) is NotImplemented
)
assert Version.parse("1.0.0").__eq__(SemVerSubclass.parse("1.0.0")) is True

assert SemVerSubclass.parse("1.0.0") == Version.parse("1.0.0")
assert Version.parse("1.0.0") == SemVerSubclass.parse("1.0.0")
Loading