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

Trivial changes: improved documentations for __contains__ #21619

Closed
wants to merge 1 commit into from

Conversation

alkeldi
Copy link

@alkeldi alkeldi commented Jul 25, 2020

The previous strings for list.__contains__.__doc__ and tuple.__contains__.__doc__ were "Return key in self.". This is misleading, because __contains__ returns a boolean.

I modified these strings and the string in set.__contains__.__doc__ to a semilar format of that in dict.__contains__.__doc__.

@alkeldi alkeldi requested a review from rhettinger as a code owner Jul 25, 2020
@the-knights-who-say-ni
Copy link

the-knights-who-say-ni commented Jul 25, 2020

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@alkeldi

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@rhettinger
Copy link
Contributor

rhettinger commented Jul 28, 2020

How is the current wording misleading? I don't follow what you're saying about returning a boolean.

Also, I think we're losing something important if the docstrings for dunder methods stops telling users about the associated operators, __eq__(self, other) called by self==value and __contains__(self, key) called by key in self.

@alkeldi
Copy link
Author

alkeldi commented Jul 28, 2020

I think the misleading part is Return key in self because it suggests returning a key that exists in self. However, the returned value is the boolean result of the in operator. It's not clear that in is meant to be the operator. What's happening here is basically documenting code with another code, but that's not clear.

As for the other modification, which is in the set-object, it's just to make the docstrings for all the basic datatypes similar.

Another way to do this, is making the docstrings =x.__contains__(y) <==> y in x for all the datatypes. In this context it's easier to see that in is the operator.

Also, dict has __contains__.__doc__ = True if the dictionary has the specified key, else False., which doesn't mention anything about the associated operator.

@rhettinger
Copy link
Contributor

rhettinger commented Jul 31, 2020

I'm going to unassign from this one. I don't really buy into the notion that people are going to misread the docstring and believe that d.__contains__(key) is going to "return some other key from the dict". I've never encountered anyone who read it that way.

@alkeldi alkeldi closed this Aug 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants