-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
set boolean false as type of empty class #9121
set boolean false as type of empty class #9121
Conversation
b36b7e8
to
2883bee
Compare
@@ -46,7 +46,19 @@ | |||
logger = logging.getLogger("rest_framework.fields") | |||
|
|||
|
|||
class empty: | |||
class EmptyType(type): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure about the usage of the proposed change. can you share some examples and possibly unit/integrations tests as well to verify the changes proposed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in #9120 it's a bit explained but I'll rewrite it here anyway.
I think that when making comparisons with data whose value is empty
you can consider it as False
.
in the case I explained in #9120
data = empty
if not data:
here you would be saying that data is None
, False
, ""
, []
or is empty
.
Co-authored-by: Rodolfo Becerra <[email protected]>
6e773d4
to
552d128
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty is a sentinel value, used with is
explicitly to distinguish from
False
or None
.
@carltongibson are you expressing an opinion against here? You weren’t explicit. I’m against it because it’s backward incompatible for code like: if not x:
thing1()
elif x is empty:
thing2() A slightly odd way to write it but still valid. I don’t think there’s a reasonable deprecation path here. |
Yes, sorry. To be explicit: I don't see any positive reason for this change (and many potential issues). I'd be 👎 |
thanks folks |
Description
https://github.com/encode/django-rest-framework/discussions/9120