-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Open
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dir
Description
Documentation
During a discussion on idea of minimizing requirements for children of collections.abc.Sequence, it was pointed out, that documentation is currently lacking sufficient description on expected behaviour of method __getitem__.
The part in question starts with first note after __length_hint__ description. I started by writing, to see what's missing. Non-trivial changes include:.
- Translation of
a[1:2, 3:5]intoa[(slice(1, 2, None), slice(3, 5, None))]. - Because that translation exist, custom behaviour types (like matrix) are also supported.
- Slicing should return object of the same type, or at least similar.
- If description is good, then note about for loops is unnecessary. (Plus it's outdated, for loops call
iterandnext, the iterator calls__getitem__). - One object can implement both protocols correctly (at the same time).
- Setting
__iter__toNonemakesiternot fallback to sequence protocol. (And similar point forreversed). - Having ABC as parent, or explicitly assigning methods from them, isn't worst than not defining them at all.
- (After coping fallback description from
__reversed__, correct that)iterdon't need full sequence protocol, just__getitem__method.
Linked PRs
Metadata
Metadata
Assignees
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dir