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

bpo-47122: Fix the table of methods in the collections.abc documentation #32090

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

geryogam
Copy link
Contributor

@geryogam geryogam commented Mar 23, 2022

This pull request makes the following changes to the table of methods in the collections.abc documentation:

  • Reversible: add __iter__ abstract method;
  • Generator: replace __iter__ with inherited mixin Iterator method;
  • MutableSequence: add clear mixin method;
  • Set: remove __ne__ mixin method (not defined here but in object), add __rand__ mixin method, add __ror__ mixin method, add __rsub__ mixin method, add __rxor__ mixin method;
  • Mapping: remove __ne__ mixin method (not defined here but in object);
  • ItemsView: add inherited mixin MappingView method and inherited mixin Set methods;
  • KeysView: add inherited mixin MappingView method and inherited mixin Set methods;
  • ValuesView: add inherited mixin MappingView method;
  • Coroutine: add __await__ abstract method;
  • AsyncGenerator: replace __aiter__ with inherited mixin AsyncIterator method;
  • footnotes: remove footnote 2 which is a duplicate of collections.abc.Iterable description.

https://bugs.python.org/issue47122

@bedevere-bot bedevere-bot added the docs Documentation in the Doc dir label Mar 23, 2022
@geryogam geryogam changed the title Add inheritance to footnotes Improve collections.abc documentation Mar 23, 2022
@geryogam geryogam changed the title Improve collections.abc documentation Fix the table of methods in the collections.abc documentation Mar 25, 2022
@geryogam geryogam marked this pull request as ready for review March 25, 2022 18:22
@geryogam geryogam changed the title Fix the table of methods in the collections.abc documentation bpo-47122: Fix the table of methods in the collections.abc documentation Mar 25, 2022
@rhettinger rhettinger self-assigned this Mar 25, 2022
:class:`Collection` [1]_ :class:`Sized`, ``__contains__``,
:class:`Reversible` [1]_ :class:`Iterable` ``__reversed__``,
``__iter__``
:class:`Generator` [1]_ :class:`Iterator` ``send``, Inherited mixin :class:`Iterator` method,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave the Generator as is. The "inherited" references are used only when the would copy a lot of methods. The current form for this entry is more readable, useful, and easy to understand.

Doc/library/collections.abc.rst Show resolved Hide resolved
``__setitem__``, ``pop``, ``popitem``, ``clear``, ``update``,
``__delitem__``, and ``setdefault``
``__delitem__``, ``setdefault``
``__iter__``,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't do these minor stylistic edits. It makes the table harder to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted most of them.

Doc/library/collections.abc.rst Outdated Show resolved Hide resolved
``__iter__``, ``clear``, ``pop``, ``remove``, ``__ior__``,
``__len__``, ``__iand__``, ``__ixor__``, and ``__isub__``
``__contains__``, ``__iand__``, ``__ixor__``, ``__isub__``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Github diff makes it difficult to see what exactly what is changing here. Are you taking out the required len method, if so why?

Also put the "and" back in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the unfriendly diff. I did not remove __len__, I just reordered the abstract methods from contains, iter, len to len, iter, contains, so that it matches the order of the inherited classes Sized, Iterable, Container of Collection to improve readibility.

I also removed the ‘and’ for readability as it looks like the __and__ method, and because it was not used consistently in the table (every list of three items or more should have it).

What do you think?

:class:`Set` ``__iter__``
:class:`ValuesView` :class:`MappingView`, ``__contains__``, ``__iter__``
:class:`Collection`
:class:`ItemsView` :class:`MappingView`, Inherited mixin :class:`MappingView` method,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This group of edits is harsh on the eyes. I don't see how they add any value. ISTM these all refactor the presentation style in a way that makes the table even harder to read and use.

@@ -220,7 +213,7 @@ Collections Abstract Base Classes -- Detailed Descriptions
ABC for classes that provide the :meth:`__iter__` method.

Checking ``isinstance(obj, Iterable)`` detects classes that are registered
as :class:`Iterable` or that have an :meth:`__iter__` method, but it does
as or inherit from :class:`Iterable`, or that have an :meth:`__iter__` method, but it does
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably unnecessary. First, isinstance() always detects direct inheritance so that does need to be repeated every time we talk about isinstance(). Second, all classes that inherit from Iterable will already have an iter method so that case is covered by the current sentence.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@rhettinger
Copy link
Contributor

Can you make a simplified version of this PR that sticks to fixing entries that are incorrect (like the missing clear method) rather than stylistic edits (eliding "and", general restyling, propagating the "inherited from" wording, general wording edits, etc.)?

This table has been very successful in help users, but it is already challenging to read. IMO a number of these edits make less approachable or useful for day to day programming. With some of the edits a user would be better of running dir(cls) or cls.__abstractmethods__ than trying to read the revised table.

@geryogam
Copy link
Contributor Author

Thanks for the review. Sorry for the unfriendly diff: I have reverted the reordering of the methods and the removal of newlines after multiline entries. I have also restored footnote 2 and removed the propagation of the ‘inherited from’ wording for single inherited methods as suggested. Finally, I have commented about the elided ‘and’. This will hopefully make the P.R. more reviewable.

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@rhettinger: please review the changes made to this pull request.


:class:`MutableSequence` :class:`Sequence` ``__getitem__``, Inherited :class:`Sequence` methods and
:class:`MutableSequence` :class:`Sequence` ``__getitem__``, Inherited mixin :class:`Sequence` methods,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the benefit of adding the word mixin here?

A downside is that readers may wonder if mixin methods or inherited mixin methods are a special thing, which they aren’t. So I would not add the word, inherited Sequence methods is fine.

Copy link
Contributor Author

@geryogam geryogam Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is to refer only to mixing methods of the parent class, as the other parent methods do not belong to this column.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants