summaryrefslogtreecommitdiff
path: root/Lib/typing.py
diff options
context:
space:
mode:
authorPatrick Reader <pxeger@protonmail.com>2020-09-16 05:58:32 +0100
committerGitHub <noreply@github.com>2020-09-15 21:58:32 -0700
commit0705ec8a149e27023b0420ae0366d16255f6c9f7 (patch)
treecc477b4be6306f9b2007f4d2084440e7c965a643 /Lib/typing.py
parent22415ad62555d79bd583b4a7d6a96006624a8277 (diff)
downloadcpython-git-0705ec8a149e27023b0420ae0366d16255f6c9f7.tar.gz
bpo-41792: Add is_typeddict function to typing.py (GH-22254)
Closes issue41792. Also closes https://github.com/python/typing/issues/751.
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 2aedbeb852..8c61bd8e08 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -103,6 +103,7 @@ __all__ = [
'get_args',
'get_origin',
'get_type_hints',
+ 'is_typeddict',
'NewType',
'no_type_check',
'no_type_check_decorator',
@@ -1479,6 +1480,20 @@ def get_args(tp):
return ()
+def is_typeddict(tp):
+ """Check if an annotation is a TypedDict class
+
+ For example::
+ class Film(TypedDict):
+ title: str
+ year: int
+
+ is_typeddict(Film) # => True
+ is_typeddict(Union[list, str]) # => False
+ """
+ return isinstance(tp, _TypedDictMeta)
+
+
def no_type_check(arg):
"""Decorator to indicate that annotations are not type hints.