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

Skip to content

Fix #316: Return NotImplemented for comparisons #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2020
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
10 changes: 10 additions & 0 deletions changelog.d/316.trivial.rst
Original file line number Diff line number Diff line change
@@ -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
4 changes: 1 addition & 3 deletions src/semver/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down