|
7 | 7 | import typing |
8 | 8 | from collections import deque |
9 | 9 | from types import UnionType |
10 | | -from typing import Any, Deque, Dict, FrozenSet, List, Optional, Set, Tuple, Union |
| 10 | +from typing import Any, Callable, Deque, Dict, FrozenSet, List, Optional, Set, Tuple, Union |
11 | 11 |
|
12 | 12 | import pytest |
13 | 13 |
|
|
80 | 80 | pytest.param("tuple[dict]", tuple[dict]), |
81 | 81 | pytest.param("tuple[float]", tuple[float]), |
82 | 82 | pytest.param("tuple[bool]", tuple[bool]), |
| 83 | + # variadic tuple (the `...` is the Ellipsis singleton, not a type) |
| 84 | + pytest.param("tuple[int, ...]", tuple[int, ...]), |
| 85 | + pytest.param("tuple[str, ...]", tuple[str, ...]), |
| 86 | + pytest.param("tuple[dict[str, int], ...]", tuple[dict[str, int], ...]), |
83 | 87 | # typing Tuple |
84 | 88 | pytest.param("typing.Tuple", Tuple), |
85 | 89 | pytest.param("typing.Tuple[int]", Tuple[int]), |
86 | 90 | pytest.param("typing.Tuple[str]", Tuple[str]), |
87 | 91 | pytest.param("typing.Tuple[dict]", Tuple[dict]), |
88 | 92 | pytest.param("typing.Tuple[float]", Tuple[float]), |
89 | 93 | pytest.param("typing.Tuple[bool]", Tuple[bool]), |
| 94 | + pytest.param("typing.Tuple[int, ...]", Tuple[int, ...]), |
| 95 | + # callable (the `...` is the Ellipsis singleton, not a type) |
| 96 | + pytest.param("typing.Callable[..., int]", Callable[..., int]), |
| 97 | + pytest.param("typing.Callable[..., str]", Callable[..., str]), |
90 | 98 | # PEP 604 X | Y |
91 | 99 | pytest.param("str | int", str | int), |
92 | 100 | pytest.param("int | float", int | float), |
@@ -245,6 +253,12 @@ def test_output_type_round_trip_typing_generic_with_nonetype(): |
245 | 253 | assert deserialize_type(serialize_type(type_)) == type_ |
246 | 254 |
|
247 | 255 |
|
| 256 | +def test_output_type_deserialization_legacy_ellipsis_literal(): |
| 257 | + # Types serialized by older versions emitted the literal "Ellipsis"; make sure they still load. |
| 258 | + assert deserialize_type("tuple[int, Ellipsis]") == tuple[int, ...] |
| 259 | + assert deserialize_type("typing.Callable[Ellipsis, int]") == Callable[..., int] |
| 260 | + |
| 261 | + |
248 | 262 | def test_output_type_serialization_haystack_dataclasses(): |
249 | 263 | # typing |
250 | 264 | # Answer |
|
0 commit comments