|
5 | 5 | import os |
6 | 6 | import pathlib |
7 | 7 | import re |
| 8 | +import sys |
8 | 9 | from typing import Any, Callable, Dict, List, Optional, Pattern, Tuple, Type, Union |
9 | 10 |
|
| 11 | +if sys.version_info >= (3, 10): |
| 12 | + from typing import TypeAlias as _TypeAlias |
| 13 | +else: |
| 14 | + _TypeAlias = type |
| 15 | + |
10 | 16 | from ._common import is_final_class |
11 | 17 | from ._optionals import final, pydantic_support |
12 | 18 | from ._util import Path, get_import_path, get_private_kwargs, import_object |
@@ -58,7 +64,7 @@ def extend_base_type( |
58 | 64 | docstring: Optional[str] = None, |
59 | 65 | extra_attrs: Optional[dict] = None, |
60 | 66 | register_key: Optional[Tuple] = None, |
61 | | -) -> type: |
| 67 | +) -> _TypeAlias: |
62 | 68 | """Creates and registers an extension of base type. |
63 | 69 |
|
64 | 70 | Args: |
@@ -103,7 +109,7 @@ def restricted_number_type( |
103 | 109 | restrictions: Union[Tuple, List[Tuple]], |
104 | 110 | join: str = "and", |
105 | 111 | docstring: Optional[str] = None, |
106 | | -) -> type: |
| 112 | +) -> _TypeAlias: |
107 | 113 | """Creates or returns an already registered restricted number type class. |
108 | 114 |
|
109 | 115 | Args: |
@@ -174,7 +180,7 @@ def restricted_string_type( |
174 | 180 | name: str, |
175 | 181 | regex: Union[str, Pattern], |
176 | 182 | docstring: Optional[str] = None, |
177 | | -) -> type: |
| 183 | +) -> _TypeAlias: |
178 | 184 | """Creates or returns an already registered restricted string type class. |
179 | 185 |
|
180 | 186 | Args: |
@@ -213,7 +219,7 @@ def _is_path_type(value, type_class): |
213 | 219 | return isinstance(value, Path) |
214 | 220 |
|
215 | 221 |
|
216 | | -def path_type(mode: str, docstring: Optional[str] = None, **kwargs) -> type: |
| 222 | +def path_type(mode: str, docstring: Optional[str] = None, **kwargs) -> _TypeAlias: |
217 | 223 | """Creates or returns an already registered path type class. |
218 | 224 |
|
219 | 225 | Args: |
|
0 commit comments