Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.12] gh-115570: Fix DeprecationWarnings in test_typing (#115571) #115574

Merged
merged 1 commit into from Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions Lib/test/test_typing.py
Expand Up @@ -8123,6 +8123,17 @@ def test_re_submodule(self):
self.assertEqual(__name__, 'typing.re')
self.assertEqual(len(w), 1)

def test_re_submodule_access_basics(self):
with warnings.catch_warnings():
warnings.filterwarnings("error", category=DeprecationWarning)
from typing import re
self.assertIsInstance(re.__doc__, str)
self.assertEqual(re.__name__, "typing.re")
self.assertIsInstance(re.__dict__, types.MappingProxyType)

with self.assertWarns(DeprecationWarning):
re.Match

def test_cannot_subclass(self):
with self.assertRaisesRegex(
TypeError,
Expand Down
4 changes: 2 additions & 2 deletions Lib/typing.py
Expand Up @@ -3256,11 +3256,11 @@ def __enter__(self) -> 'TextIO':

class _DeprecatedType(type):
def __getattribute__(cls, name):
if name not in ("__dict__", "__module__") and name in cls.__dict__:
if name not in {"__dict__", "__module__", "__doc__"} 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.",
"in Python 3.13.",
DeprecationWarning,
stacklevel=2,
)
Expand Down
@@ -0,0 +1,3 @@
A :exc:`DeprecationWarning` is no longer omitted on access to the
``__doc__`` attributes of the deprecated ``typing.io`` and ``typing.re``
pseudo-modules.