|
5 | 5 | from mypy_extensions import TypedDict
|
6 | 6 | """
|
7 | 7 |
|
8 |
| -from typing import Any |
| 8 | +from typing import Any, Dict |
9 | 9 |
|
10 | 10 | import sys
|
11 | 11 | # _type_check is NOT a part of public typing API, it is used here only to mimic
|
@@ -150,7 +150,8 @@ def KwArg(type=Any):
|
150 | 150 |
|
151 | 151 |
|
152 | 152 | # Return type that indicates a function does not return
|
153 |
| -class NoReturn: pass |
| 153 | +# Deprecated, use typing or typing_extensions variants instead |
| 154 | +class _DEPRECATED_NoReturn: pass |
154 | 155 |
|
155 | 156 |
|
156 | 157 | def trait(cls):
|
@@ -226,3 +227,25 @@ def __new__(cls, x=0, base=_sentinel):
|
226 | 227 | * isinstance(x, {name}) is the same as isinstance(x, int)
|
227 | 228 | """.format(name=_int_type.__name__)
|
228 | 229 | del _int_type
|
| 230 | + |
| 231 | + |
| 232 | +def _warn_deprecation(name: str, module_globals: Dict[str, Any]) -> Any: |
| 233 | + if (val := module_globals.get(f"_DEPRECATED_{name}")) is None: |
| 234 | + msg = f"module '{__name__}' has no attribute '{name}'" |
| 235 | + raise AttributeError(msg) |
| 236 | + module_globals[name] = val |
| 237 | + if name in {"NoReturn"}: |
| 238 | + msg = ( |
| 239 | + f"'mypy_extensions.{name}' is deprecated, " |
| 240 | + "and will be removed in a future version. " |
| 241 | + f"Use 'typing.{name}' or 'typing_extensions.{name}' instead" |
| 242 | + ) |
| 243 | + else: |
| 244 | + assert False, f"Add deprecation message for 'mypy_extensions.{name}'" |
| 245 | + import warnings |
| 246 | + warnings.warn(msg, DeprecationWarning, stacklevel=3) |
| 247 | + return val |
| 248 | + |
| 249 | + |
| 250 | +def __getattr__(name: str) -> Any: |
| 251 | + return _warn_deprecation(name, module_globals=globals()) |
0 commit comments