Title: bpo-30969: Fix docs about the comparison in absence of __contains__ by ztane · Pull Request #2761 · python/cpython · GitHub
Open Graph Title: bpo-30969: Fix docs about the comparison in absence of __contains__ by ztane · Pull Request #2761 · python/cpython
X Title: bpo-30969: Fix docs about the comparison in absence of __contains__ by ztane · Pull Request #2761 · python/cpython
Description: The documentation doesn't match the implementation, which clearly does x is y or x == y to check if x is the element y from a container. Both the __iter__ and the index-iteration method test the elements using is first. While the document says that x is x means that x == x should be true, it is not true for example in the case of nan:
>>> x == x
False
>>> x is x
True```
The following demonstrates the behaviour that is against the documented behaviour:
```>>> class Foo:
... def __iter__(self):
... return iter([x])
...
>>> x in Foo()
True
>>> any(x == i for i in Foo())
False
>>> class Bar:
... def __getitem__(self):
... return [x].__getitem__(self)
...
>>> class Bar:
... def __getitem__(self, i):
... return [x].__getitem__(i)
...
>>> x in Bar
Traceback (most recent call last):
File "
Open Graph Description: The documentation doesn't match the implementation, which clearly does x is y or x == y to check if x is the element y from a container. Both the __iter__ and the index-iteration method test th...
X Description: The documentation doesn't match the implementation, which clearly does x is y or x == y to check if x is the element y from a container. Both the __iter__ and the index-iteration method tes...
Opengraph URL: https://github.com/python/cpython/pull/2761
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files/:range(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:bbc20df3-5ba8-d7af-27fb-783a02c7be04 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 92E4:321365:4A8A3D8:62FAE5F:69959863 |
| html-safe-nonce | d2a0b320996fb754f406ce86693cc0e2770fe0203435baf3f63168e71c59c667 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MkU0OjMyMTM2NTo0QThBM0Q4OjYyRkFFNUY6Njk5NTk4NjMiLCJ2aXNpdG9yX2lkIjoiMTYzNjkyMDg4NTYzMzE5NDA4MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6037111b729b86f07238cd59f9519f61889fcf763853e7fcc2e53dc6cdabb2a6 |
| hovercard-subject-tag | pull_request:131303361 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/2761/files/b4f285f984545eac6f141ff40fb27b97c9acc926 |
| twitter:image | https://avatars.githubusercontent.com/u/704200?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/704200?s=400&v=4 |
| og:image:alt | The documentation doesn't match the implementation, which clearly does x is y or x == y to check if x is the element y from a container. Both the __iter__ and the index-iteration method test th... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4bd759bc5f83244e2a0de29b937365905c0fefd238b6f077c24a49830375b4df |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 6de0b4814d356b3d1ba4b5c6f757c6d4b967559b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width