Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upbpo-39425: Document list.count() corner case #18130
Conversation
This comment has been minimized.
This comment has been minimized.
cc @corona10 |
This comment has been minimized.
This comment has been minimized.
FYI CPython 3.7.2, CPython master branch, PyPy 7.1.1 and PyPy3 7.1.1-beta0 all give the same result:
|
@@ -994,6 +994,11 @@ Notes: | |||
without copying any data and with the returned index being relative to | |||
the start of the sequence rather than the start of the slice. | |||
|
|||
(9) | |||
In CPython, :meth:`tuple.count` and :meth:`list.count` consider that an |
This comment has been minimized.
This comment has been minimized.
ammaraskar
Jan 22, 2020
Member
I would suggest rephrasing to:
In CPython,
tuple.count
andlist.count
consider an element to be equal to x if it is identical to x (ifelement is x
is true) skipping the call to element's__eq__()
method.
or maybe even
skipping the result of
element == x
for the last part.
This comment has been minimized.
This comment has been minimized.
I don't think this is a good idea, at least not on its own. The behavior is all over the place. For example, off the top of my head, in |
This comment has been minimized.
This comment has been minimized.
Can we document it somewhere else in this case? |
This comment has been minimized.
This comment has been minimized.
For all I know, it already is Because |
This comment has been minimized.
This comment has been minimized.
If it is, I would not say that it's not well documented :-) For example, it's not mentionnned in the Maybe this method documentation would be a better place to describe CPython quirks? |
This comment has been minimized.
This comment has been minimized.
I suggest taking this to python-dev. It's not at all clear to me that this is just a pile of CPython quirks. For example, whether a NaN can be used as a dict key is something that "should" be defined by the language. Or if consensus is that this is just a pile of CPython quirks, then they need to be documented as such. Note that |
vstinner commentedJan 22, 2020
•
edited by bedevere-bot
https://bugs.python.org/issue39425