summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_typing.py
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2023-05-24 18:46:00 (GMT)
committerGitHub <noreply@github.com>2023-05-24 18:46:00 (GMT)
commit1497607a8e99f1103c40368dd5f9057f0146a520 (patch)
treec0137a221a5ca4ab46b80d8d7aa2029f90dbe05d /Lib/test/test_typing.py
parentc90a862cdcf55dc1753c6466e5fa4a467a13ae24 (diff)
downloadcpython-1497607a8e99f1103c40368dd5f9057f0146a520.zip
cpython-1497607a8e99f1103c40368dd5f9057f0146a520.tar.gz
cpython-1497607a8e99f1103c40368dd5f9057f0146a520.tar.bz2
Improve test coverage for is_typeddict (#104884)
In particular, it's important to test that is_typeddict(TypedDict) returns False.
Diffstat (limited to 'Lib/test/test_typing.py')
-rw-r--r--Lib/test/test_typing.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 098933b..76c9e39 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -7223,10 +7223,29 @@ class TypedDictTests(BaseTestCase):
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)
+
+ class NewGeneric[T](TypedDict):
+ a: T
+ self.assertIs(is_typeddict(NewGeneric), True)
+ self.assertIs(is_typeddict(NewGeneric[int]), False)
+ self.assertIs(is_typeddict(NewGeneric()), False)
+
+ # The TypedDict constructor is not itself a TypedDict
+ self.assertIs(is_typeddict(TypedDict), False)
def test_get_type_hints(self):
self.assertEqual(