|
| 1 | +import sys |
| 2 | +import typing |
1 | 3 | from typing import * # necessary for eval() |
2 | 4 |
|
3 | 5 | from pedantic.type_checking_logic.check_types import get_type_arguments |
@@ -96,18 +98,18 @@ def _parse_documented_type(type_: str, context: Dict[str, Any], err: str) -> Any |
96 | 98 | <class 'float'> |
97 | 99 | >>> _parse_documented_type(type_='List[List[bool]]', context={}, err='') |
98 | 100 | typing.List[typing.List[bool]] |
99 | | - >>> _parse_documented_type(type_='Union[int, float, str]', context={}, err='') |
100 | | - typing.Union[int, float, str] |
| 101 | + >>> typing.Union[int, float, str] == _parse_documented_type(type_='Union[int, float, str]', context={}, err='') # 3.13: typing.Union[int, float, str], 3.14: int | float | str |
| 102 | + True |
101 | 103 | >>> _parse_documented_type(type_='Callable[[int, bool, str], float]', context={}, err='') |
102 | 104 | typing.Callable[[int, bool, str], float] |
103 | | - >>> _parse_documented_type(type_='Optional[List[Dict[str, float]]]', context={}, err='') |
104 | | - typing.Optional[typing.List[typing.Dict[str, float]]] |
105 | | - >>> _parse_documented_type(type_='Optional[List[Dict[str, float]]]', context={}, err='') |
106 | | - typing.Optional[typing.List[typing.Dict[str, float]]] |
107 | | - >>> _parse_documented_type(type_='Union[List[Dict[str, float]], None]', context={}, err='') |
108 | | - typing.Optional[typing.List[typing.Dict[str, float]]] |
109 | | - >>> _parse_documented_type(type_='Union[List[Dict[str, float]], None]', context={}, err='') |
110 | | - typing.Optional[typing.List[typing.Dict[str, float]]] |
| 105 | + >>> typing.Optional[typing.List[typing.Dict[str, float]]] == _parse_documented_type(type_='Optional[List[Dict[str, float]]]', context={}, err='') # 3.13: typing.Optional[typing.List[typing.Dict[str, float]]], 3.14: typing.List[typing.Dict[str, float]] | None |
| 106 | + True |
| 107 | + >>> typing.Optional[typing.List[typing.Dict[str, float]]] == _parse_documented_type(type_='Optional[List[Dict[str, float]]]', context={}, err='') |
| 108 | + True |
| 109 | + >>> typing.Optional[typing.List[typing.Dict[str, float]]] == _parse_documented_type(type_='Union[List[Dict[str, float]], None]', context={}, err='') |
| 110 | + True |
| 111 | + >>> typing.Optional[typing.List[typing.Dict[str, float]]] == _parse_documented_type(type_='Union[List[Dict[str, float]], None]', context={}, err='') |
| 112 | + True |
111 | 113 | >>> _parse_documented_type(type_='MyClass', context={}, err='') |
112 | 114 | Traceback (most recent call last): |
113 | 115 | ... |
@@ -157,8 +159,10 @@ def _update_context(context: Dict[str, Any], type_: Any) -> Dict[str, Any]: |
157 | 159 | {'str': <class 'str'>} |
158 | 160 | >>> _update_context(type_=List[List[bool]], context={}) |
159 | 161 | {'bool': <class 'bool'>} |
160 | | - >>> _update_context(type_=Union[int, float, str], context={}) |
| 162 | + >>> _update_context(type_=Union[int, float, str], context={}) if sys.version_info < (3, 14) else {'int': int, 'float': float, 'str': str} |
161 | 163 | {'int': <class 'int'>, 'float': <class 'float'>, 'str': <class 'str'>} |
| 164 | + >>> _update_context(type_=Union[int, float, str], context={}) if sys.version_info >= (3, 14) else {'Union': Union[int, float, str]} |
| 165 | + {'Union': int | float | str} |
162 | 166 | >>> _update_context(type_=Callable[[int, bool, str], float], context={}) |
163 | 167 | {'int': <class 'int'>, 'bool': <class 'bool'>, 'str': <class 'str'>, 'float': <class 'float'>} |
164 | 168 | >>> _update_context(type_=Optional[List[Dict[str, float]]], context={}) |
|
0 commit comments