[Python-checkins] [3.11] Improve test coverage for is_typeddict (GH-104884) (#104888)

JelleZijlstra webhook-mailer at python.org
Wed May 24 15:23:41 EDT 2023


https://github.com/python/cpython/commit/5e911673e4e3cbf16dfa6dd624fa7a2187b4a8a7
commit: 5e911673e4e3cbf16dfa6dd624fa7a2187b4a8a7
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: JelleZijlstra <jelle.zijlstra at gmail.com>
date: 2023-05-24T19:23:35Z
summary:

[3.11] Improve test coverage for is_typeddict (GH-104884) (#104888)

In particular, it's important to test that is_typeddict(TypedDict)
returns False.
(cherry picked from commit 1497607a8e99f1103c40368dd5f9057f0146a520)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra at gmail.com>

files:
M Lib/test/test_typing.py

diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index e36cab601621..5cb4356a8c69 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -6756,10 +6756,23 @@ class Wrong(*bases):
                         pass
 
     def test_is_typeddict(self):
-        assert is_typeddict(Point2D) is True
-        assert is_typeddict(Union[str, int]) is False
+        self.assertIs(is_typeddict(Point2D), True)
+        self.assertIs(is_typeddict(Union[str, int]), False)
         # classes, not instances
-        assert is_typeddict(Point2D()) is False
+        self.assertIs(is_typeddict(Point2D()), False)
+        call_based = TypedDict('call_based', {'a': int})
+        self.assertIs(is_typeddict(call_based), True)
+        self.assertIs(is_typeddict(call_based()), False)
+
+        T = TypeVar("T")
+        class BarGeneric(TypedDict, Generic[T]):
+            a: T
+        self.assertIs(is_typeddict(BarGeneric), True)
+        self.assertIs(is_typeddict(BarGeneric[int]), False)
+        self.assertIs(is_typeddict(BarGeneric()), False)
+
+        # The TypedDict constructor is not itself a TypedDict
+        self.assertIs(is_typeddict(TypedDict), False)
 
     def test_get_type_hints(self):
         self.assertEqual(



More information about the Python-checkins mailing list