_frozenbidict.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2018 Joshua Bronson. All Rights Reserved.
  3. #
  4. # This Source Code Form is subject to the terms of the Mozilla Public
  5. # License, v. 2.0. If a copy of the MPL was not distributed with this
  6. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. #==============================================================================
  8. # * Welcome to the bidict source code *
  9. #==============================================================================
  10. # Doing a code review? You'll find a "Code review nav" comment like the one
  11. # below at the top and bottom of the most important source files. This provides
  12. # a suggested initial path through the source when reviewing.
  13. #
  14. # Note: If you aren't reading this on https://github.com/jab/bidict, you may be
  15. # viewing an outdated version of the code. Please head to GitHub to review the
  16. # latest version, which contains important improvements over older versions.
  17. #
  18. # Thank you for reading and for any feedback you provide.
  19. # * Code review nav *
  20. #==============================================================================
  21. # ← Prev: _base.py Current: _frozenbidict.py Next: _mut.py →
  22. #==============================================================================
  23. """Provides :class:`frozenbidict`, an immutable, hashable bidirectional mapping type."""
  24. from ._base import BidictBase
  25. from ._proxied import _ProxiedKeysValsItems
  26. from .compat import ItemsView
  27. class frozenbidict(_ProxiedKeysValsItems, BidictBase): # noqa: N801; pylint: disable=invalid-name
  28. """Immutable, hashable bidict type."""
  29. __slots__ = ()
  30. def __hash__(self): # lgtm [py/equals-hash-mismatch]
  31. """The hash of this bidict as determined by its items."""
  32. if getattr(self, '_hash', None) is None:
  33. # pylint: disable=protected-access,attribute-defined-outside-init
  34. self._hash = ItemsView(self)._hash()
  35. return self._hash
  36. # * Code review nav *
  37. #==============================================================================
  38. # ← Prev: _base.py Current: _frozenbidict.py Next: _mut.py →
  39. #==============================================================================