Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitabdda5b

Browse files
srittauAlexWaygoodJelleZijlstra
authored
gh-92871: Remove typing.{io,re} namespaces (#92873)
Closes#92871Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent9dc476b commitabdda5b

File tree

5 files changed

+7
-76
lines changed

5 files changed

+7
-76
lines changed

‎Doc/library/typing.rst‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,10 +2074,6 @@ Other concrete types
20742074
represent the types of I/O streams such as returned by
20752075
:func:`open`.
20762076

2077-
..deprecated-removed::3.8 3.13
2078-
The ``typing.io`` namespace is deprecated and will be removed.
2079-
These types should be directly imported from ``typing`` instead.
2080-
20812077
..class::Pattern
20822078
Match
20832079

@@ -2088,10 +2084,6 @@ Other concrete types
20882084
``Pattern[str]``, ``Pattern[bytes]``, ``Match[str]``, or
20892085
``Match[bytes]``.
20902086

2091-
..deprecated-removed::3.8 3.13
2092-
The ``typing.re`` namespace is deprecated and will be removed.
2093-
These types should be directly imported from ``typing`` instead.
2094-
20952087
..deprecated::3.9
20962088
Classes ``Pattern`` and ``Match`` from:mod:`re` now support ``[]``.
20972089
See:pep:`585` and:ref:`types-genericalias`.
@@ -2981,9 +2973,6 @@ convenience. This is subject to change, and not all deprecations are listed.
29812973
+----------------------------------+---------------+-------------------+----------------+
29822974
| Feature| Deprecated in| Projected removal| PEP/issue|
29832975
+==================================+===============+===================+================+
2984-
| ``typing.io`` and ``typing.re``| 3.8| 3.13|:issue:`38291`|
2985-
| submodules||||
2986-
+----------------------------------+---------------+-------------------+----------------+
29872976
| ``typing`` versions of standard| 3.9| Undecided|:pep:`585`|
29882977
| collections||||
29892978
+----------------------------------+---------------+-------------------+----------------+

‎Doc/whatsnew/3.13.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ Removed
107107
`Exscript<https://pypi.org/project/Exscript/>`_ instead.
108108
(Contributed by Victor Stinner in:gh:`104773`.)
109109

110+
* Namespaces ``typing.io`` and ``typing.re``, deprecated in Python 3.8,
111+
are now removed. The items in those namespaces can be imported directly
112+
from:mod:`typing`. (Contributed by Sebastian Rittau in:gh:`92871`.)
110113

111114
Porting to Python 3.13
112115
======================

‎Lib/test/test_typing.py‎

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7529,17 +7529,6 @@ def stuff(a: BinaryIO) -> bytes:
75297529
a=stuff.__annotations__['a']
75307530
self.assertEqual(a.__parameters__, ())
75317531

7532-
deftest_io_submodule(self):
7533-
withwarnings.catch_warnings(record=True)asw:
7534-
warnings.filterwarnings("default",category=DeprecationWarning)
7535-
fromtyping.ioimportIO,TextIO,BinaryIO,__all__,__name__
7536-
self.assertIs(IO,typing.IO)
7537-
self.assertIs(TextIO,typing.TextIO)
7538-
self.assertIs(BinaryIO,typing.BinaryIO)
7539-
self.assertEqual(set(__all__),set(['IO','TextIO','BinaryIO']))
7540-
self.assertEqual(__name__,'typing.io')
7541-
self.assertEqual(len(w),1)
7542-
75437532

75447533
classRETests(BaseTestCase):
75457534
# Much of this is really testing _TypeAlias.
@@ -7584,16 +7573,6 @@ def test_repr(self):
75847573
self.assertEqual(repr(Match[str]),'typing.Match[str]')
75857574
self.assertEqual(repr(Match[bytes]),'typing.Match[bytes]')
75867575

7587-
deftest_re_submodule(self):
7588-
withwarnings.catch_warnings(record=True)asw:
7589-
warnings.filterwarnings("default",category=DeprecationWarning)
7590-
fromtyping.reimportMatch,Pattern,__all__,__name__
7591-
self.assertIs(Match,typing.Match)
7592-
self.assertIs(Pattern,typing.Pattern)
7593-
self.assertEqual(set(__all__),set(['Match','Pattern']))
7594-
self.assertEqual(__name__,'typing.re')
7595-
self.assertEqual(len(w),1)
7596-
75977576
deftest_cannot_subclass(self):
75987577
withself.assertRaisesRegex(
75997578
TypeError,
@@ -8765,7 +8744,7 @@ def test_all(self):
87658744
# Context managers.
87668745
self.assertIn('ContextManager',a)
87678746
self.assertIn('AsyncContextManager',a)
8768-
# Check that io and re are not exported.
8747+
# Check thatformer namespacesio and re are not exported.
87698748
self.assertNotIn('io',a)
87708749
self.assertNotIn('re',a)
87718750
# Spot-check that stdlib modules aren't exported.
@@ -8785,7 +8764,6 @@ def test_all_exported_names(self):
87858764
ifkinactual_allor (
87868765
# avoid private names
87878766
notk.startswith('_')and
8788-
knotin {'io','re'}and
87898767
# there's a few types and metaclasses that aren't exported
87908768
notk.endswith(('Meta','_contra','_co'))and
87918769
notk.upper()==kand

‎Lib/typing.py‎

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
no_type_check_decorator.
1717
* Generic aliases for collections.abc ABCs and few additional protocols.
1818
* Special types: NewType, NamedTuple, TypedDict.
19-
* Wrapper submodules for re and io related types.
2019
"""
2120

2221
fromabcimportabstractmethod,ABCMeta
@@ -27,7 +26,7 @@
2726
importcontextlib
2827
importfunctools
2928
importoperator
30-
importreasstdlib_re# Avoid confusion with the rewe export.
29+
importreasstdlib_re# Avoid confusion with thetyping.renamespace on <=3.11
3130
importsys
3231
importtypes
3332
importwarnings
@@ -158,10 +157,6 @@
158157
'Unpack',
159158
]
160159

161-
# The pseudo-submodules 're' and 'io' are part of the public
162-
# namespace, but excluded from __all__ because they might stomp on
163-
# legitimate imports of those modules.
164-
165160

166161
def_type_convert(arg,module=None,*,allow_special_forms=False):
167162
"""For converting None to type(None), and strings to ForwardRef."""
@@ -3150,45 +3145,9 @@ def __enter__(self) -> 'TextIO':
31503145
pass
31513146

31523147

3153-
class_DeprecatedType(type):
3154-
def__getattribute__(cls,name):
3155-
ifnamenotin ("__dict__","__module__")andnameincls.__dict__:
3156-
warnings.warn(
3157-
f"{cls.__name__} is deprecated, import directly "
3158-
f"from typing instead.{cls.__name__} will be removed "
3159-
"in Python 3.12.",
3160-
DeprecationWarning,
3161-
stacklevel=2,
3162-
)
3163-
returnsuper().__getattribute__(name)
3164-
3165-
3166-
classio(metaclass=_DeprecatedType):
3167-
"""Wrapper namespace for IO generic classes."""
3168-
3169-
__all__= ['IO','TextIO','BinaryIO']
3170-
IO=IO
3171-
TextIO=TextIO
3172-
BinaryIO=BinaryIO
3173-
3174-
3175-
io.__name__=__name__+'.io'
3176-
sys.modules[io.__name__]=io
3177-
31783148
Pattern=_alias(stdlib_re.Pattern,1)
31793149
Match=_alias(stdlib_re.Match,1)
31803150

3181-
classre(metaclass=_DeprecatedType):
3182-
"""Wrapper namespace for re type aliases."""
3183-
3184-
__all__= ['Pattern','Match']
3185-
Pattern=Pattern
3186-
Match=Match
3187-
3188-
3189-
re.__name__=__name__+'.re'
3190-
sys.modules[re.__name__]=re
3191-
31923151

31933152
defreveal_type[T](obj:T,/)->T:
31943153
"""Reveal the inferred type of a variable.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove the ``typing.io`` and ``typing.re`` namespaces, deprecated since Python
2+
3.8. All items are still available from the main:mod:`typing` module.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp