From 2857d69d3451617e3a4a5de2ace401ff3e80513a Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Fri, 1 Nov 2024 00:57:55 +0100 Subject: [PATCH] Sydney's feedback --- peps/pep-0764.rst | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/peps/pep-0764.rst b/peps/pep-0764.rst index 4026384f8..d74b1e65c 100644 --- a/peps/pep-0764.rst +++ b/peps/pep-0764.rst @@ -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 ` (the dictionary keys are strings representing the field names, and values are valid :ref:`annotation expressions `). -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