-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Why isn't "in" called a comparison operation? #72803
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
Comments
Regarding
There is a line at the bottom claiming:
The claim is incorrect because Is there any good reason why we don't include them in the table of comparison operations, and say that there are ten comparison operations in python? They do support comparison chaining in the same way: >>> 'x' in 'xy' in 'xyz'
True
>>> 0 in {0} in [{0}]
True |
It should really say "only by types that support iteration". They are not comparison operations, they are containment predicates. |
Well, that wouldn't be true either. Because you can easily implement objects which support membership tests but don't support iteration. |
I want to add that the grammar explicitly mentions them as comparisons
And they are also listed in the comparisons section of the expressions documentation
So the docs seem to be contradicting themselves here. |
At a grammar and implementation level, the "in" and "not in" operators are treated like comparisons (same precedence and opcodes), but at a semantic level, I concur with David Murray and don't think of these as being comparisons at all. Accordingly, I prefer the current presentation |
Perhaps it's better to call a spade a spade here - if they're implemented as comparisons, then why not document them as comparisons? A colleague has mentioned one point that sets Here is an alternate patch which leaves the table alone, but corrects the inaccuracy in the note. |
"in" and "not in" are not comparisons, regardless of implementation mechanics (which could change). They aren't really dependent on iteration, though they often correlate with iteration. I'd rather see them described as "containment tests" or something similar. |
newpatch.diff looks fine. |
"Two more operations with the same syntactic priority, in and not in, are supported ..." could be changed to The containment tests in and not in have the same priority as comparisons and are supported ..." |
1 month later.. is newpatch.diff OK to merge or any further improvements needed? thanks |
Also see https://bugs.python.org/issue32055 regarding the prospect of bringing the implementation into line with the intuitive semantics, and preventing implicit comparison chaining for containment tests. |
I think that "types that are :term:`iterable` or implement the :meth:`__contains__` method" is too low-level for this section. In this section we tell about builtin types. From those the types that support |
Humm, why the bot merges in the master branch? |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: