From 5d53627da30bed9015e925aad9f0234c6eea4b55 Mon Sep 17 00:00:00 2001 From: Rodolfo Becerra Date: Thu, 28 Sep 2023 12:46:14 +0200 Subject: [PATCH] set booleant false as type of empty class --- rest_framework/fields.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 0b56fa7fb..0118b8db8 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -46,7 +46,19 @@ from rest_framework.validators import ProhibitSurrogateCharactersValidator logger = logging.getLogger("rest_framework.fields") -class empty: +class EmptyType(type): + """ + Metaclass for overriding the boolean representation of a class. + + When a class uses this metaclass, its type (the class itself, not its instances) + will evaluate to `False` in boolean contexts. + """ + + def __bool__(self): + return False + + +class empty(metaclass=EmptyType): """ This class is used to represent no data being provided for a given input or output value.