From c59e8cc275776ef428462ccdd61a99f0d5ab2820 Mon Sep 17 00:00:00 2001 From: Allan Lewis Date: Wed, 29 Jun 2022 10:32:49 +0100 Subject: [PATCH] exceptions.ErrorDetail: Handle `NotImplemented` correctly in `__ne__` 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__`. --- rest_framework/exceptions.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rest_framework/exceptions.py b/rest_framework/exceptions.py index fee8f024f2..d216067706 100644 --- a/rest_framework/exceptions.py +++ b/rest_framework/exceptions.py @@ -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)' % (