bazarr/libs/bidict/_frozenordered.py

50 lines
2.1 KiB
Python
Raw Normal View History

2022-11-07 18:06:49 +00:00
# Copyright 2009-2022 Joshua Bronson. All rights reserved.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# * Code review nav *
2022-11-07 18:06:49 +00:00
# (see comments in __init__.py)
#==============================================================================
#← Prev: _orderedbase.py Current: _frozenordered.py Next: _orderedbidict.py →
#==============================================================================
"""Provide :class:`FrozenOrderedBidict`, an immutable, hashable, ordered bidict."""
2022-11-07 18:06:49 +00:00
import typing as t
from ._frozenbidict import frozenbidict
from ._orderedbase import OrderedBidictBase
from ._typing import KT, VT
class FrozenOrderedBidict(OrderedBidictBase[KT, VT]):
"""Hashable, immutable, ordered bidict type.
Like a hashable :class:`bidict.OrderedBidict`
without the mutating APIs, or like a
reversible :class:`bidict.frozenbidict` even on Python < 3.8.
(All bidicts are order-preserving when never mutated, so frozenbidict is
already order-preserving, but only on Python 3.8+, where dicts are
reversible, are all bidicts (including frozenbidict) also reversible.)
If you are using Python 3.8+, frozenbidict gives you everything that
FrozenOrderedBidict gives you, but with less space overhead.
2022-11-07 18:06:49 +00:00
On the other hand, using FrozenOrderedBidict when you are depending on
the ordering of the items can make the ordering dependence more explicit.
"""
2022-11-07 18:06:49 +00:00
__hash__: t.Callable[[t.Any], int] = frozenbidict.__hash__ # pyright: ignore
2022-11-07 18:06:49 +00:00
if t.TYPE_CHECKING:
@property
def inverse(self) -> 'FrozenOrderedBidict[VT, KT]': ...
# * Code review nav *
#==============================================================================
#← Prev: _orderedbase.py Current: _frozenordered.py Next: _orderedbidict.py →
#==============================================================================