Sydney's feedback
This commit is contained in:
parent
2e0c379b42
commit
2857d69d34
|
@ -39,7 +39,7 @@ times, it is used to return or accept structured data in functions. However,
|
|||
it can get tedious to define :class:`~typing.TypedDict` classes:
|
||||
|
||||
* A typed dictionary requires a name, which might not be relevant.
|
||||
* Nested dictionaries requires more than one class definition.
|
||||
* Nested dictionaries require more than one class definition.
|
||||
|
||||
Taking a simple function returning some nested structured data as an example::
|
||||
|
||||
|
@ -82,6 +82,9 @@ used), inlined typed dictionaries can be assigned to a variable, as an alias::
|
|||
|
||||
InlinedTD = TypedDict[{'name': str}]
|
||||
|
||||
def get_movie() -> InlinedTD:
|
||||
...
|
||||
|
||||
|
||||
Specification
|
||||
=============
|
||||
|
@ -92,7 +95,7 @@ semantics as the :ref:`functional syntax <typing:typeddict-functional-syntax>`
|
|||
(the dictionary keys are strings representing the field names, and values are
|
||||
valid :ref:`annotation expressions <typing:annotation-expression>`).
|
||||
|
||||
Inlined typed dictionaries can be referred as being *anonymous*, meaning they
|
||||
Inlined typed dictionaries can be referred to as *anonymous*, meaning they
|
||||
don't have a name. For this reason, their :attr:`~type.__name__` attribute
|
||||
will be set to an empty string.
|
||||
|
||||
|
@ -125,7 +128,7 @@ are bound to some outer scope::
|
|||
reveal_type(fn('a')['name']) # Revealed type is 'str'
|
||||
|
||||
|
||||
type InlinedTD[T] = TypedDict[{'name': T}] # OK
|
||||
type InlinedTD[T] = TypedDict[{'name': T}] # OK, `T` is scoped to the type alias.
|
||||
|
||||
|
||||
T = TypeVar('T')
|
||||
|
@ -154,8 +157,8 @@ Although :class:`~typing.TypedDict` is commonly referred as a class, it is
|
|||
implemented as a function at runtime. To be made subscriptable, it will be
|
||||
changed to be a class.
|
||||
|
||||
Creating an inlined typed dictionary results in a new class, so both syntaxes
|
||||
return the same type (apart from the different :attr:`~type.__name__`)::
|
||||
Creating an inlined typed dictionary results in a new class, so ``T1`` and
|
||||
``T2`` are the same type (apart from the different :attr:`~type.__name__`)::
|
||||
|
||||
from typing import TypedDict
|
||||
|
||||
|
|
Loading…
Reference in New Issue