@@ -32,8 +32,10 @@ def test_annotations_from_classes() -> None:
3232 assert returns .canonical_path == f"{ module .name } .A"
3333
3434
35+ # YORE: EOL 3.13: Remove block.
3536# YORE: EOL 3.9: Remove line.
3637@pytest .mark .skipif (sys .version_info < (3 , 10 ), reason = "Type unions not supported on 3.9" )
38+ @pytest .mark .skipif (sys .version_info >= (3 , 14 ), reason = "3.14 changes type annotations, see test below" )
3739@pytest .mark .parametrize (
3840 ("annotation" , "expected" ),
3941 [
@@ -43,6 +45,29 @@ def test_annotations_from_classes() -> None:
4345 ("int | Literal[1]" , "typing.Union[int, typing.Literal[1]]" ),
4446 ],
4547)
48+ def test_annotations_from_types_before_314 (annotation : str , expected : str ) -> None :
49+ """Assert annotations are correctly converted to string."""
50+ with temporary_inspected_module (
51+ f"""
52+ from typing import Literal, Union
53+ def func(param: { annotation } ): ...
54+ """ ,
55+ ) as module :
56+ param = module ["func" ].parameters ["param" ]
57+ assert str (param .annotation ) == expected
58+
59+
60+ # YORE: EOL 3.13: Remove line.
61+ @pytest .mark .skipif (sys .version_info < (3 , 14 ), reason = "3.14 modernizes type unions" )
62+ @pytest .mark .parametrize (
63+ ("annotation" , "expected" ),
64+ [
65+ ("tuple[int, str]" , "tuple[int, str]" ),
66+ ("Union[int, str]" , "int | str" ),
67+ ("int | str" , "int | str" ),
68+ ("int | Literal[1]" , "int | typing.Literal[1]" ),
69+ ],
70+ )
4671def test_annotations_from_types (annotation : str , expected : str ) -> None :
4772 """Assert annotations are correctly converted to string."""
4873 with temporary_inspected_module (
0 commit comments