mirror of
https://github.com/python/cpython.git
synced 2025-08-09 11:29:45 +00:00
[3.12] Improve test coverage for is_typeddict (GH-104884) (#104889)
Improve test coverage for is_typeddict (GH-104884)
In particular, it's important to test that is_typeddict(TypedDict)
returns False.
(cherry picked from commit 1497607a8e
)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
ddc29c8fdb
commit
3d91d034a0
1 changed files with 22 additions and 3 deletions
|
@ -7223,10 +7223,29 @@ class TypedDictTests(BaseTestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_is_typeddict(self):
|
def test_is_typeddict(self):
|
||||||
assert is_typeddict(Point2D) is True
|
self.assertIs(is_typeddict(Point2D), True)
|
||||||
assert is_typeddict(Union[str, int]) is False
|
self.assertIs(is_typeddict(Union[str, int]), False)
|
||||||
# classes, not instances
|
# 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):
|
def test_get_type_hints(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue