_structures.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. # This file is dual licensed under the terms of the Apache License, Version
  2. # 2.0, and the BSD License. See the LICENSE file in the root of this repository
  3. # for complete details.
  4. """Backward-compatibility shim for unpickling Version objects serialized before
  5. packaging 26.1.
  6. Old pickles reference ``packaging._structures.InfinityType`` and
  7. ``packaging._structures.NegativeInfinityType``. This module provides minimal
  8. stand-in classes so that ``pickle.loads()`` can resolve those references.
  9. The deserialized objects are not used for comparisons — ``Version.__setstate__``
  10. discards the stale ``_key`` cache and recomputes it from the core version fields.
  11. """
  12. from __future__ import annotations
  13. class InfinityType:
  14. """Stand-in for the removed ``InfinityType`` used in old comparison keys."""
  15. def __repr__(self) -> str:
  16. return "Infinity"
  17. class NegativeInfinityType:
  18. """Stand-in for the removed ``NegativeInfinityType`` used in old comparison keys."""
  19. def __repr__(self) -> str:
  20. return "-Infinity"
  21. Infinity = InfinityType()
  22. NegativeInfinity = NegativeInfinityType()