Skip to content

Commit

Permalink
[3.11] Improve test coverage for is_typeddict (GH-104884) (#104888)
Browse files Browse the repository at this point in the history
In particular, it's important to test that is_typeddict(TypedDict)
returns False.
(cherry picked from commit 1497607)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
  • Loading branch information
miss-islington and JelleZijlstra authored May 24, 2023
1 parent fa7d8ce commit 5e91167
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 5e91167

Please sign in to comment.