# Copyright 2009-2024 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 *# (see comments in __init__.py)# ============================================================================# ← Prev: _base.py Current: _frozen.py Next: _bidict.py →# ============================================================================"""Provide :class:`frozenbidict`, an immutable, hashable bidirectional mapping type."""from__future__importannotationsimporttypingastfrom._baseimportBidictBasefrom._typingimportKTfrom._typingimportVTclassfrozenbidict(BidictBase[KT,VT]):"""Immutable, hashable bidict type."""_hash:intift.TYPE_CHECKING:@propertydefinverse(self)->frozenbidict[VT,KT]:...@propertydefinv(self)->frozenbidict[VT,KT]:...
[docs]def__hash__(self)->int:"""The hash of this bidict as determined by its items."""ifgetattr(self,'_hash',None)isNone:# The following is like hash(frozenset(self.items()))# but more memory efficient. See also: https://bugs.python.org/issue46684self._hash=t.ItemsView(self)._hash()returnself._hash