Skip to content

Containers

operator operand
expression function type method type
len(_) do_len DoesLen __len__ CanLen
_.__length_hint__() (docs) do_length_hint DoesLengthHint __length_hint__ CanLengthHint
_[k] do_getitem DoesGetitem __getitem__ CanGetitem[-K, +V]
_.__missing__() (docs) do_missing DoesMissing __missing__ CanMissing[-K, +D]
_[k] = v do_setitem DoesSetitem __setitem__ CanSetitem[-K, -V]
del _[k] do_delitem DoesDelitem __delitem__ CanDelitem[-K]
k in _ do_contains DoesContains __contains__ CanContains[-K=object]
reversed(_) do_reversed DoesReversed __reversed__ CanReversed[+R], or
CanSequence[-I, +V]

Because CanMissing[K, D] generally doesn't show itself without CanGetitem[K, V] there to hold its hand, optype conveniently stitched them together as optype.CanGetMissing[K, V, D=V].

Similarly, there is optype.CanSequence[K: CanIndex | slice, V], which is the combination of both CanLen and CanItem[I, V], and serves as a more specific and flexible collections.abc.Sequence[V].