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

Skip to content

Commit c75737d

Browse files
authored
Merge pull request #318 from tomschr/bugfix/316-notimplemented
Fix #316: Return NotImplemented for comparisons
2 parents 44708ef + 6793320 commit c75737d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

changelog.d/316.trivial.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Comparisons of :class:`~semver.version.Version` class and other
2+
types return now a :py:const:`NotImplemented` constant instead
3+
of a :py:exc:`TypeError` exception.
4+
5+
The `NotImplemented`_ section of the Python documentation recommends
6+
returning this constant when comparing with ``__gt__``, ``__lt__``,
7+
and other comparison operators to "to indicate that the operation is
8+
not implemented with respect to the other type".
9+
10+
.. _NotImplemented: https://docs.python.org/3/library/constants.html#NotImplemented

src/semver/version.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ def wrapper(self: "Version", other: Comparable) -> bool:
7272
*String.__args__, # type: ignore
7373
)
7474
if not isinstance(other, comparable_types):
75-
raise TypeError(
76-
"other type %r must be in %r" % (type(other), comparable_types)
77-
)
75+
return NotImplemented
7876
return operator(self, other)
7977

8078
return wrapper

0 commit comments

Comments
 (0)