.. _jgdv._abstract.protocols.stdlib: =============================== jgdv._abstract.protocols.stdlib =============================== .. py:module:: jgdv._abstract.protocols.stdlib .. autoapi-nested-parse:: An Adaptation of typeshed's protocol's of the stdlib. Protocols --------- .. autoapisummary:: jgdv._abstract.protocols.stdlib.Buffer_p jgdv._abstract.protocols.stdlib.Callable_p jgdv._abstract.protocols.stdlib.Collection_p jgdv._abstract.protocols.stdlib.Container_p jgdv._abstract.protocols.stdlib.Generator_p jgdv._abstract.protocols.stdlib.Hashable_p jgdv._abstract.protocols.stdlib.ItemsView_p jgdv._abstract.protocols.stdlib.Iterable_p jgdv._abstract.protocols.stdlib.Iterator_p jgdv._abstract.protocols.stdlib.KeysView_p jgdv._abstract.protocols.stdlib.MappingView_p jgdv._abstract.protocols.stdlib.Mapping_p jgdv._abstract.protocols.stdlib.MutableMapping_p jgdv._abstract.protocols.stdlib.MutableSequence_p jgdv._abstract.protocols.stdlib.MutableSet_p jgdv._abstract.protocols.stdlib.Reversible_p jgdv._abstract.protocols.stdlib.Sequence_p jgdv._abstract.protocols.stdlib.Set_p jgdv._abstract.protocols.stdlib.Sized_p jgdv._abstract.protocols.stdlib.ValuesView_p Module Contents =============== .. _jgdv._abstract.protocols.stdlib.Buffer_p: .. py:class:: Buffer_p Bases: :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing). For example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto[T](Protocol): def meth(self) -> T: ... .. _jgdv._abstract.protocols.stdlib.Callable_p: .. py:class:: Callable_p Bases: :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing). For example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto[T](Protocol): def meth(self) -> T: ... .. _jgdv._abstract.protocols.stdlib.Collection_p: .. py:class:: Collection_p Bases: :py:obj:`Sized_p`, :py:obj:`Iterable_p`, :py:obj:`Container_p`, :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing). For example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto[T](Protocol): def meth(self) -> T: ... .. _jgdv._abstract.protocols.stdlib.Container_p: .. py:class:: Container_p Bases: :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing). For example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto[T](Protocol): def meth(self) -> T: ... .. _jgdv._abstract.protocols.stdlib.Generator_p: .. py:class:: Generator_p Bases: :py:obj:`Iterator_p`, :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing). For example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto[T](Protocol): def meth(self) -> T: ... .. py:method:: close() -> .. py:method:: send(value) -> .. py:method:: throw(typ, val = None, tb = None) -> .. _jgdv._abstract.protocols.stdlib.Hashable_p: .. py:class:: Hashable_p Bases: :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing). For example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto[T](Protocol): def meth(self) -> T: ... .. _jgdv._abstract.protocols.stdlib.ItemsView_p: .. py:class:: ItemsView_p(mapping) Bases: :py:obj:`MappingView_p`, :py:obj:`Set_p`, :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing). For example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto[T](Protocol): def meth(self) -> T: ... .. py:method:: _from_iterable(it) -> :classmethod: .. _jgdv._abstract.protocols.stdlib.Iterable_p: .. py:class:: Iterable_p Bases: :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing). For example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto[T](Protocol): def meth(self) -> T: ... .. _jgdv._abstract.protocols.stdlib.Iterator_p: .. py:class:: Iterator_p Bases: :py:obj:`Iterable_p`, :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing). For example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto[T](Protocol): def meth(self) -> T: ... .. _jgdv._abstract.protocols.stdlib.KeysView_p: .. py:class:: KeysView_p(mapping) Bases: :py:obj:`MappingView_p`, :py:obj:`Set_p`, :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing). For example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto[T](Protocol): def meth(self) -> T: ... .. py:method:: _from_iterable(it) -> :classmethod: .. _jgdv._abstract.protocols.stdlib.MappingView_p: .. py:class:: MappingView_p(mapping) Bases: :py:obj:`Sized_p`, :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing). For example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto[T](Protocol): def meth(self) -> T: ... .. _jgdv._abstract.protocols.stdlib.Mapping_p: .. py:class:: Mapping_p Bases: :py:obj:`Collection_p`, :py:obj:`Protocol` A Mapping_p is a generic container for associating key/value pairs. This class provides concrete generic implementations of all methods except for __getitem__, __iter__, and __len__. .. py:method:: get(key, default = None) -> .. py:method:: items() -> .. py:method:: keys() -> .. py:method:: values() -> .. _jgdv._abstract.protocols.stdlib.MutableMapping_p: .. py:class:: MutableMapping_p Bases: :py:obj:`Mapping_p`\ [\ :py:obj:`MutableMapping_p.K`\ , :py:obj:`MutableMapping_p.V`\ ], :py:obj:`Protocol` A MutableMapping is a generic container for associating key/value pairs. This class provides concrete generic implementations of all methods except for __getitem__, __setitem__, __delitem__, __iter__, and __len__. .. py:method:: clear() -> .. py:method:: pop(key, default = None) -> .. py:method:: popitem() -> .. py:method:: setdefault(key, default = None) -> .. py:method:: update(other = (), /, **kwds) -> .. _jgdv._abstract.protocols.stdlib.MutableSequence_p: .. py:class:: MutableSequence_p Bases: :py:obj:`Sequence_p`, :py:obj:`Protocol` All the operations on a read-write sequence. Concrete subclasses must provide __new__ or __init__, __getitem__, __setitem__, __delitem__, __len__, and insert(). .. py:method:: append(value) -> .. py:method:: clear() -> .. py:method:: extend(values) -> .. py:method:: insert(index, value) -> .. py:method:: pop(index = -1) -> .. py:method:: remove(value) -> .. py:method:: reverse() -> .. _jgdv._abstract.protocols.stdlib.MutableSet_p: .. py:class:: MutableSet_p Bases: :py:obj:`Set_p`\ [\ :py:obj:`MutableSet_p.V`\ ], :py:obj:`Protocol` A mutable set is a finite, iterable container. This class provides concrete generic implementations of all methods except for __contains__, __iter__, __len__, add(), and discard(). To override the comparisons (presumably for speed, as the semantics are fixed), all you have to do is redefine __le__ and then the other operations will automatically follow suit. .. py:method:: add(value) -> .. py:method:: clear() -> .. py:method:: discard(value) -> .. py:method:: pop() -> .. py:method:: remove(value) -> .. _jgdv._abstract.protocols.stdlib.Reversible_p: .. py:class:: Reversible_p Bases: :py:obj:`Iterable_p`, :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing). For example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto[T](Protocol): def meth(self) -> T: ... .. _jgdv._abstract.protocols.stdlib.Sequence_p: .. py:class:: Sequence_p Bases: :py:obj:`Reversible_p`, :py:obj:`Collection_p`, :py:obj:`Protocol` All the operations on a read-only sequence. Concrete subclasses must override __new__ or __init__, __getitem__, and __len__. .. py:method:: count(value) -> .. py:method:: index(value, start = 0, stop = None) -> .. _jgdv._abstract.protocols.stdlib.Set_p: .. py:class:: Set_p Bases: :py:obj:`Collection_p`, :py:obj:`Protocol` A set is a finite, iterable container. This class provides concrete generic implementations of all methods except for __contains__, __iter__ and __len__. To override the comparisons (presumably for speed, as the semantics are fixed), redefine __le__ and __ge__, then the other operations will automatically follow suit. .. py:method:: _from_iterable(it) -> :classmethod: .. py:method:: _hash() -> .. py:method:: isdisjoint(other) -> .. _jgdv._abstract.protocols.stdlib.Sized_p: .. py:class:: Sized_p Bases: :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing). For example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto[T](Protocol): def meth(self) -> T: ... .. _jgdv._abstract.protocols.stdlib.ValuesView_p: .. py:class:: ValuesView_p(mapping) Bases: :py:obj:`MappingView_p`, :py:obj:`Collection_p`, :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing). For example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto[T](Protocol): def meth(self) -> T: ...