-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-109812: Fix phrasing for collections.Counter
#109813
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! It is up to @rhettinger to decide on the wording, but the bug in the docs is clear! 👍
Congrats on your first CPython PR!
It is always nice to see familiar people 😉
Doc/library/collections.rst
Outdated
@@ -358,7 +358,7 @@ Common patterns for working with :class:`Counter` objects:: | |||
list(c) # list unique elements | |||
set(c) # convert to a set | |||
dict(c) # convert to a regular dictionary | |||
c.items() # convert to a list of (elem, cnt) pairs | |||
c.items() # convert to a view object of the dictionary’s items (elem, cnt) pairs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just
c.items() # convert to a view object of the dictionary’s items (elem, cnt) pairs | |
c.items() # convert to a iterator of (elem, cnt) pairs |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not an iterator.
I'd just change "list" to "view". And "convert to" to "create", since the view doesn't really contain the data, so "convert to" seems wrong to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is just an iterable 👍
>>> {}.items().__iter__
<method-wrapper '__iter__' of dict_items object at 0x102cd1250>
>>> {}.items().__next__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'dict_items' object has no attribute '__next__'. Did you mean: '__ne__'?
Doc/library/collections.rst
Outdated
@@ -358,7 +358,7 @@ Common patterns for working with :class:`Counter` objects:: | |||
list(c) # list unique elements | |||
set(c) # convert to a set | |||
dict(c) # convert to a regular dictionary | |||
c.items() # convert to a list of (elem, cnt) pairs | |||
c.items() # create a view of the dictionary’s items (elem, cnt) pairs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is more in line with the rest of the examples
c.items() # create a view of the dictionary’s items (elem, cnt) pairs | |
list(c.items()) # convert to a list of (elem, cnt) pairs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree. The doc for c.items() should say what c.items returns.
Nitpick. The docs were correct when they were written (Python 2.7). It is the parent class that changed. You all are welcome to change this to This spirit of the section is about how we use counters, so I would opt for:
|
I agree on |
0ae00cb
to
fbfec56
Compare
- fail at squashing 7 commits for one line change Signed-off-by: Jacob Coffee <[email protected]>
This changes the wording for an incorrect
collections.Counter
piece.collections.Counter
docs #109812📚 Documentation preview 📚: https://cpython-previews--109813.org.readthedocs.build/