From 52e12d9ef6885692c9c89bb0bf7510daf4f7c5b3 Mon Sep 17 00:00:00 2001 From: David Smith Date: Wed, 9 Sep 2020 22:01:26 +0100 Subject: [PATCH] Return NotImplemented sooner for ErrorDetail equality test The test suite raises warnings when tested against Python 3.9 `DeprecationWarning: NotImplemented should not be used in a boolean context` Where `r` returns `NotImplemented` then this change returns `NotImplemented` first to avoid the comparison test. --- rest_framework/exceptions.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rest_framework/exceptions.py b/rest_framework/exceptions.py index 345a405248..943dcc88c3 100644 --- a/rest_framework/exceptions.py +++ b/rest_framework/exceptions.py @@ -73,6 +73,8 @@ def __new__(cls, string, code=None): def __eq__(self, other): r = super().__eq__(other) + if r is NotImplemented: + return NotImplemented try: return r and self.code == other.code except AttributeError: