bidict/docs/other-bidict-types.rst

62 lines
1.6 KiB
ReStructuredText

.. _other-bidict-types:
Other ``bidict`` Types
======================
Now that we've covered
:doc:`basic-usage` with the :class:`bidict.bidict` type,
let's look at some other bidirectional mapping types.
.. _bidict-types-diagram:
``bidict`` Types Diagram
------------------------
.. image:: _static/bidict-types-diagram.png
:alt: bidict types diagram
The most abstract class that :mod:`bidict` provides is
the :class:`bidict.BidirectionalMapping` ABC.
This extends :class:`collections.abc.Mapping`
by adding the
":attr:`~bidict.BidirectionalMapping.inv`"
:obj:`~abc.abstractproperty`.
All bidirectional mapping types that :mod:`bidict` provides
are subclasses of :class:`bidict.BidirectionalMapping`.
(In fact, any :class:`collections.abc.Mapping`
that provides an ``inv`` attribute
will be considered a virtual subclass of
:class:`bidict.BidirectionalMapping`
:meth:`automatically <bidict.BidirectionalMapping.__subclasshook__>`,
enabling interoperability with external implementations.)
As you may have noticed,
:class:`bidict.bidict` is also
a :class:`collections.abc.MutableMapping`.
But :mod:`bidict` provides
immutable bidirectional mapping types as well.
.. include:: frozenbidict.rst.inc
.. include:: orderedbidict.rst.inc
:class:`~bidict.FrozenOrderedBidict`
------------------------------------
:class:`~bidict.FrozenOrderedBidict`
is an immutable ordered bidict type.
It's like an :class:`~bidict.OrderedBidict`
without the mutating APIs,
or equivalently like an order-preserving
:class:`~bidict.frozenbidict`.
.. include:: namedbidict.rst.inc
.. include:: polymorphism.rst.inc
.. include:: extending.rst.inc
Next proceed to :ref:`other-functionality`.