Skip to content

Commit

Permalink
exceptions.ErrorDetail: Handle NotImplemented correctly in __ne__ (
Browse files Browse the repository at this point in the history
…#8538)

PR #7531 resolved issue #7433 by updating `ErrorDetails.__eq__` to correctly
handle the `NotImplemented` case. However, Python 3.9 continues to issue the
following warning:

    DeprecationWarning: NotImplemented should not be used in a boolean context

This is because `__ne__` still doesn't handle the `NotImplemented` case
correctly. In order to avoid this warning, this commit makes the same change
for `__ne__` as previously made for `__eq__`.
  • Loading branch information
allanlewis authored Aug 1, 2022
1 parent a1b35bb commit 224168a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion rest_framework/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ def __eq__(self, other):
return r

def __ne__(self, other):
return not self.__eq__(other)
r = self.__eq__(other)
if r is NotImplemented:
return NotImplemented
return not r

def __repr__(self):
return 'ErrorDetail(string=%r, code=%r)' % (
Expand Down

0 comments on commit 224168a

Please sign in to comment.