mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-92871: Remove typing.{io,re} namespaces (#92873)
Closes #92871 Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
9dc476be2d
commit
abdda5b133
5 changed files with 7 additions and 76 deletions
|
@ -16,7 +16,6 @@ At large scale, the structure of the module is following:
|
|||
no_type_check_decorator.
|
||||
* Generic aliases for collections.abc ABCs and few additional protocols.
|
||||
* Special types: NewType, NamedTuple, TypedDict.
|
||||
* Wrapper submodules for re and io related types.
|
||||
"""
|
||||
|
||||
from abc import abstractmethod, ABCMeta
|
||||
|
@ -27,7 +26,7 @@ import copyreg
|
|||
import contextlib
|
||||
import functools
|
||||
import operator
|
||||
import re as stdlib_re # Avoid confusion with the re we export.
|
||||
import re as stdlib_re # Avoid confusion with the typing.re namespace on <=3.11
|
||||
import sys
|
||||
import types
|
||||
import warnings
|
||||
|
@ -158,10 +157,6 @@ __all__ = [
|
|||
'Unpack',
|
||||
]
|
||||
|
||||
# The pseudo-submodules 're' and 'io' are part of the public
|
||||
# namespace, but excluded from __all__ because they might stomp on
|
||||
# legitimate imports of those modules.
|
||||
|
||||
|
||||
def _type_convert(arg, module=None, *, allow_special_forms=False):
|
||||
"""For converting None to type(None), and strings to ForwardRef."""
|
||||
|
@ -3150,45 +3145,9 @@ class TextIO(IO[str]):
|
|||
pass
|
||||
|
||||
|
||||
class _DeprecatedType(type):
|
||||
def __getattribute__(cls, name):
|
||||
if name not in ("__dict__", "__module__") 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']
|
||||
IO = IO
|
||||
TextIO = TextIO
|
||||
BinaryIO = BinaryIO
|
||||
|
||||
|
||||
io.__name__ = __name__ + '.io'
|
||||
sys.modules[io.__name__] = io
|
||||
|
||||
Pattern = _alias(stdlib_re.Pattern, 1)
|
||||
Match = _alias(stdlib_re.Match, 1)
|
||||
|
||||
class re(metaclass=_DeprecatedType):
|
||||
"""Wrapper namespace for re type aliases."""
|
||||
|
||||
__all__ = ['Pattern', 'Match']
|
||||
Pattern = Pattern
|
||||
Match = Match
|
||||
|
||||
|
||||
re.__name__ = __name__ + '.re'
|
||||
sys.modules[re.__name__] = re
|
||||
|
||||
|
||||
def reveal_type[T](obj: T, /) -> T:
|
||||
"""Reveal the inferred type of a variable.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue