|
2 | 2 | # 2.0, and the BSD License. See the LICENSE file in the root of this repository |
3 | 3 | # for complete details. |
4 | 4 |
|
5 | | -import typing |
| 5 | +"""Backward-compatibility shim for unpickling Version objects serialized before |
| 6 | +packaging 26.1. |
| 7 | +
|
| 8 | +Old pickles reference ``packaging._structures.InfinityType`` and |
| 9 | +``packaging._structures.NegativeInfinityType``. This module provides minimal |
| 10 | +stand-in classes so that ``pickle.loads()`` can resolve those references. |
| 11 | +The deserialized objects are not used for comparisons — ``Version.__setstate__`` |
| 12 | +discards the stale ``_key`` cache and recomputes it from the core version fields. |
| 13 | +""" |
| 14 | + |
| 15 | +from __future__ import annotations |
6 | 16 |
|
7 | 17 |
|
8 | | -@typing.final |
9 | 18 | class InfinityType: |
10 | | - __slots__ = () |
| 19 | + """Stand-in for the removed ``InfinityType`` used in old comparison keys.""" |
11 | 20 |
|
12 | 21 | def __repr__(self) -> str: |
13 | 22 | return "Infinity" |
14 | 23 |
|
15 | | - def __hash__(self) -> int: |
16 | | - return hash(repr(self)) |
17 | | - |
18 | | - def __lt__(self, other: object) -> bool: |
19 | | - return False |
20 | | - |
21 | | - def __le__(self, other: object) -> bool: |
22 | | - return False |
23 | | - |
24 | | - def __eq__(self, other: object) -> bool: |
25 | | - return isinstance(other, self.__class__) |
26 | | - |
27 | | - def __gt__(self, other: object) -> bool: |
28 | | - return True |
29 | | - |
30 | | - def __ge__(self, other: object) -> bool: |
31 | | - return True |
32 | | - |
33 | | - def __neg__(self: object) -> "NegativeInfinityType": |
34 | | - return NegativeInfinity |
35 | | - |
36 | | - |
37 | | -Infinity = InfinityType() |
38 | | - |
39 | 24 |
|
40 | | -@typing.final |
41 | 25 | class NegativeInfinityType: |
42 | | - __slots__ = () |
| 26 | + """Stand-in for the removed ``NegativeInfinityType`` used in old comparison keys.""" |
43 | 27 |
|
44 | 28 | def __repr__(self) -> str: |
45 | 29 | return "-Infinity" |
46 | 30 |
|
47 | | - def __hash__(self) -> int: |
48 | | - return hash(repr(self)) |
49 | | - |
50 | | - def __lt__(self, other: object) -> bool: |
51 | | - return True |
52 | | - |
53 | | - def __le__(self, other: object) -> bool: |
54 | | - return True |
55 | | - |
56 | | - def __eq__(self, other: object) -> bool: |
57 | | - return isinstance(other, self.__class__) |
58 | | - |
59 | | - def __gt__(self, other: object) -> bool: |
60 | | - return False |
61 | | - |
62 | | - def __ge__(self, other: object) -> bool: |
63 | | - return False |
64 | | - |
65 | | - def __neg__(self: object) -> InfinityType: |
66 | | - return Infinity |
67 | | - |
68 | 31 |
|
| 32 | +Infinity = InfinityType() |
69 | 33 | NegativeInfinity = NegativeInfinityType() |
0 commit comments