Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
_frozen.py51 linesDownload Raw Back to bidict
1# Copyright 2009-2024 Joshua Bronson. All rights reserved.2#3# This Source Code Form is subject to the terms of the Mozilla Public4# License, v. 2.0. If a copy of the MPL was not distributed with this5# file, You can obtain one at http://mozilla.org/MPL/2.0/.6 7 8#                             * Code review nav *9#                        (see comments in __init__.py)10# ============================================================================11# ← Prev: _base.py            Current: _frozen.py           Next: _bidict.py →12# ============================================================================13 14"""Provide :class:`frozenbidict`, an immutable, hashable bidirectional mapping type."""15 16from __future__ import annotations17 18import typing as t19 20from ._base import BidictBase21from ._typing import KT22from ._typing import VT23 24 25class frozenbidict(BidictBase[KT, VT]):26    """Immutable, hashable bidict type."""27 28    _hash: int29 30    if t.TYPE_CHECKING:31 32        @property33        def inverse(self) -> frozenbidict[VT, KT]: ...34 35        @property36        def inv(self) -> frozenbidict[VT, KT]: ...37 38    def __hash__(self) -> int:39        """The hash of this bidict as determined by its items."""40        if getattr(self, '_hash', None) is None:41            # The following is like hash(frozenset(self.items()))42            # but more memory efficient. See also: https://bugs.python.org/issue4668443            self._hash = t.ItemsView(self)._hash()44        return self._hash45 46 47#                             * Code review nav *48# ============================================================================49# ← Prev: _base.py            Current: _frozen.py           Next: _bidict.py →50# ============================================================================51 
codekingpro/portable-devtools · Team Ai