diff options
author | Sebastian Rittau <srittau@rittau.biz> | 2021-06-19 17:31:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-19 17:31:18 (GMT) |
commit | 09eb81711597725f853e4f3b659ce185488b0d8c (patch) | |
tree | 640828b6c59c0a5a94c359277edd1b7f6616bf51 /Lib/typing.py | |
parent | 291848195f85e23c01adb76d5a0ff9c6eb7f2614 (diff) | |
download | cpython-09eb81711597725f853e4f3b659ce185488b0d8c.zip cpython-09eb81711597725f853e4f3b659ce185488b0d8c.tar.gz cpython-09eb81711597725f853e4f3b659ce185488b0d8c.tar.bz2 |
bpo-38291: DeprecationWarning when importing typing.{io,re} (#26719)
Diffstat (limited to 'Lib/typing.py')
-rw-r--r-- | Lib/typing.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index 8fadb57..00a0df5 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -28,6 +28,7 @@ import operator import re as stdlib_re # Avoid confusion with the re we export. import sys import types +import warnings from types import WrapperDescriptorType, MethodWrapperType, MethodDescriptorType, GenericAlias # Please keep __all__ alphabetized within each category. @@ -2512,7 +2513,20 @@ class TextIO(IO[str]): pass -class io: +class _DeprecatedType(type): + def __getattribute__(cls, name): + if name != "__dict__" and name in cls.__dict__: + warnings.warn( + f"{cls.__name__} is deprecated, import directly " + f"from typing instead. {cls.__name__} will be removed " + "in Python 3.12.", + DeprecationWarning, + stacklevel=2, + ) + return super().__getattribute__(name) + + +class io(metaclass=_DeprecatedType): """Wrapper namespace for IO generic classes.""" __all__ = ['IO', 'TextIO', 'BinaryIO'] @@ -2527,7 +2541,7 @@ sys.modules[io.__name__] = io Pattern = _alias(stdlib_re.Pattern, 1) Match = _alias(stdlib_re.Match, 1) -class re: +class re(metaclass=_DeprecatedType): """Wrapper namespace for re type aliases.""" __all__ = ['Pattern', 'Match'] |