From 86da355eb95204a49db237046fb0379036e8a368 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 15 Mar 2024 12:17:50 +0100 Subject: [PATCH] request.py: E714 Test for object identity should be `is not` As discussed in PEP8... ```diff - return not getattr(obj, name) is Empty + return getattr(obj, name) is not Empty ``` % `ruff rule E714` # not-is-test (E714) Derived from the **pycodestyle** linter. Fix is always available. ## What it does Checks for negative comparison using `not {foo} is {bar}`. ## Why is this bad? Negative comparison should be done using `is not`. ## Example ```python if not X is Y: pass Z = not X.B is Y ``` Use instead: ```python if X is not Y: pass Z = X.B is not Y ``` --- rest_framework/request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/request.py b/rest_framework/request.py index 93109226d..d02a02613 100644 --- a/rest_framework/request.py +++ b/rest_framework/request.py @@ -87,7 +87,7 @@ class Empty: def _hasattr(obj, name): - return not getattr(obj, name) is Empty + return getattr(obj, name) is not Empty def clone_request(request, method):