]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-115570: Fix DeprecationWarnings in test_typing (#115571)
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Fri, 16 Feb 2024 19:37:42 +0000 (11:37 -0800)
committerGitHub <noreply@github.com>
Fri, 16 Feb 2024 19:37:42 +0000 (19:37 +0000)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Lib/test/test_typing.py
Lib/typing.py
Misc/NEWS.d/next/Library/2024-02-16-10-18-25.gh-issue-115570.bI6uu3.rst [new file with mode: 0644]

index 8d6d693ed08437b77558f1fdd4111f30eaf8cf6f..287e566a9b67d60ff6ccfc1f58d89261548004f3 100644 (file)
@@ -7319,6 +7319,17 @@ class RETests(BaseTestCase):
             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.assertRaises(TypeError) as ex:
 
index c62993dbd515f824210d82296067537f15ca7b24..b04ab854e105a44a660d91d1d5b22d9b3d261dd1 100644 (file)
@@ -3382,7 +3382,7 @@ class TextIO(IO[str]):
 
 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 "
diff --git a/Misc/NEWS.d/next/Library/2024-02-16-10-18-25.gh-issue-115570.bI6uu3.rst b/Misc/NEWS.d/next/Library/2024-02-16-10-18-25.gh-issue-115570.bI6uu3.rst
new file mode 100644 (file)
index 0000000..f3c8a11
--- /dev/null
@@ -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.