Skip to content
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

Conversation

rodolvbg
Copy link

@rodolvbg rodolvbg commented Sep 28, 2023

@rodolvbg rodolvbg force-pushed the set-boolean-false-as-type-of-empty-class branch from b36b7e8 to 2883bee Compare September 28, 2023 12:19
@@ -46,7 +46,19 @@
logger = logging.getLogger("rest_framework.fields")


class empty:
class EmptyType(type):
Copy link
Member

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?

Copy link
Author

@rodolvbg rodolvbg Sep 29, 2023

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.

@rodolvbg rodolvbg requested a review from auvipy September 29, 2023 11:03
@rodolvbg rodolvbg changed the title set booleant false as type of empty class set boolean false as type of empty class Sep 29, 2023
@rodolvbg rodolvbg force-pushed the set-boolean-false-as-type-of-empty-class branch from 6e773d4 to 552d128 Compare November 3, 2023 15:47
@auvipy auvipy requested a review from a team November 14, 2023 15:49
Copy link
Collaborator

@carltongibson carltongibson left a 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.

@adamchainz
Copy link
Contributor

@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.

@carltongibson
Copy link
Collaborator

Yes, sorry. To be explicit: I don't see any positive reason for this change (and many potential issues). I'd be 👎

@auvipy auvipy closed this Nov 16, 2023
@auvipy
Copy link
Member

auvipy commented Nov 16, 2023

thanks folks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants