diff --git a/changelog.d/316.trivial.rst b/changelog.d/316.trivial.rst new file mode 100644 index 00000000..edb555ff --- /dev/null +++ b/changelog.d/316.trivial.rst @@ -0,0 +1,10 @@ +Comparisons of :class:`~semver.version.Version` class and other +types return now a :py:const:`NotImplemented` constant instead +of a :py:exc:`TypeError` exception. + +The `NotImplemented`_ section of the Python documentation recommends +returning this constant when comparing with ``__gt__``, ``__lt__``, +and other comparison operators to "to indicate that the operation is +not implemented with respect to the other type". + +.. _NotImplemented: https://docs.python.org/3/library/constants.html#NotImplemented \ No newline at end of file diff --git a/src/semver/version.py b/src/semver/version.py index 40132526..4633f4bc 100644 --- a/src/semver/version.py +++ b/src/semver/version.py @@ -72,9 +72,7 @@ def wrapper(self: "Version", other: Comparable) -> bool: *String.__args__, # type: ignore ) if not isinstance(other, comparable_types): - raise TypeError( - "other type %r must be in %r" % (type(other), comparable_types) - ) + return NotImplemented return operator(self, other) return wrapper