mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
bpo-41792: Add is_typeddict function to typing.py (GH-22254)
Closes issue41792. Also closes https://github.com/python/typing/issues/751.
This commit is contained in:
parent
22415ad625
commit
0705ec8a14
4 changed files with 42 additions and 0 deletions
|
@ -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.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue