|
1 | 1 | """Tests util.typing functions.""" |
2 | 2 |
|
| 3 | +import dataclasses |
3 | 4 | import sys |
4 | 5 | import typing as t |
5 | 6 | from collections import abc |
@@ -73,6 +74,11 @@ class BrokenType: |
73 | 74 | __args__ = int |
74 | 75 |
|
75 | 76 |
|
| 77 | +@dataclasses.dataclass(frozen=True) |
| 78 | +class Gt: |
| 79 | + gt: float |
| 80 | + |
| 81 | + |
76 | 82 | def test_restify(): |
77 | 83 | assert restify(int) == ":py:class:`int`" |
78 | 84 | assert restify(int, "smart") == ":py:class:`int`" |
@@ -187,10 +193,11 @@ def test_restify_type_hints_containers(): |
187 | 193 | "[:py:obj:`None`]") |
188 | 194 |
|
189 | 195 |
|
190 | | -@pytest.mark.xfail(sys.version_info[:2] <= (3, 11), reason='Needs fixing.') |
191 | 196 | def test_restify_Annotated(): |
192 | | - assert restify(Annotated[str, "foo", "bar"]) == ':py:class:`~typing.Annotated`\\ [:py:class:`str`]' |
193 | | - assert restify(Annotated[str, "foo", "bar"], 'smart') == ':py:class:`~typing.Annotated`\\ [:py:class:`str`]' |
| 197 | + assert restify(Annotated[str, "foo", "bar"]) == ":py:class:`~typing.Annotated`\\ [:py:class:`str`, 'foo', 'bar']" |
| 198 | + assert restify(Annotated[str, "foo", "bar"], 'smart') == ":py:class:`~typing.Annotated`\\ [:py:class:`str`, 'foo', 'bar']" |
| 199 | + assert restify(Annotated[float, Gt(-10.0)]) == ':py:class:`~typing.Annotated`\\ [:py:class:`float`, Gt(gt=-10.0)]' |
| 200 | + assert restify(Annotated[float, Gt(-10.0)], 'smart') == ':py:class:`~typing.Annotated`\\ [:py:class:`float`, Gt(gt=-10.0)]' |
194 | 201 |
|
195 | 202 |
|
196 | 203 | def test_restify_type_hints_Callable(): |
@@ -499,9 +506,12 @@ def test_stringify_type_hints_pep_585(): |
499 | 506 | assert stringify_annotation(tuple[List[dict[int, str]], str, ...], "smart") == "tuple[~typing.List[dict[int, str]], str, ...]" |
500 | 507 |
|
501 | 508 |
|
| 509 | +@pytest.mark.xfail(sys.version_info[:2] <= (3, 9), reason='Needs fixing.') |
502 | 510 | def test_stringify_Annotated(): |
503 | | - assert stringify_annotation(Annotated[str, "foo", "bar"], 'fully-qualified-except-typing') == "str" |
504 | | - assert stringify_annotation(Annotated[str, "foo", "bar"], "smart") == "str" |
| 511 | + assert stringify_annotation(Annotated[str, "foo", "bar"], 'fully-qualified-except-typing') == "Annotated[str, 'foo', 'bar']" |
| 512 | + assert stringify_annotation(Annotated[str, "foo", "bar"], 'smart') == "~typing.Annotated[str, 'foo', 'bar']" |
| 513 | + assert stringify_annotation(Annotated[float, Gt(-10.0)], 'fully-qualified-except-typing') == "Annotated[float, Gt(gt=-10.0)]" |
| 514 | + assert stringify_annotation(Annotated[float, Gt(-10.0)], 'smart') == "~typing.Annotated[float, Gt(gt=-10.0)]" |
505 | 515 |
|
506 | 516 |
|
507 | 517 | def test_stringify_Unpack(): |
@@ -662,7 +672,6 @@ def test_stringify_type_hints_alias(): |
662 | 672 |
|
663 | 673 |
|
664 | 674 | def test_stringify_type_Literal(): |
665 | | - from typing import Literal # type: ignore[attr-defined] |
666 | 675 | assert stringify_annotation(Literal[1, "2", "\r"], 'fully-qualified-except-typing') == "Literal[1, '2', '\\r']" |
667 | 676 | assert stringify_annotation(Literal[1, "2", "\r"], "fully-qualified") == "typing.Literal[1, '2', '\\r']" |
668 | 677 | assert stringify_annotation(Literal[1, "2", "\r"], "smart") == "~typing.Literal[1, '2', '\\r']" |
@@ -704,8 +713,6 @@ def test_stringify_mock(): |
704 | 713 |
|
705 | 714 |
|
706 | 715 | def test_stringify_type_ForwardRef(): |
707 | | - from typing import ForwardRef # type: ignore[attr-defined] |
708 | | - |
709 | 716 | assert stringify_annotation(ForwardRef("MyInt")) == "MyInt" |
710 | 717 | assert stringify_annotation(ForwardRef("MyInt"), 'smart') == "MyInt" |
711 | 718 |
|
|
0 commit comments