Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Feb 14, 2025
1 parent 04bccd6 commit 764f867
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions peps/pep-0764.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ any :term:`typing:type qualifier` can be used for individual fields::
Inlined typed dictionaries are implicitly *total*, meaning all keys must be
present. Using the :data:`~typing.Required` type qualifier is thus redundant.

If :pep:`728` gets accepted, inlined typed dictionaries will be implicitly
:ref:`closed <typed-dict-closed>`.

Type variables are allowed in inlined typed dictionaries, provided that they
are bound to some outer scope::

Expand All @@ -137,15 +134,12 @@ are bound to some outer scope::

T = TypeVar('T')

InlinedTD = TypedDict[{'name': T}] # Not OK, `T` refers to a type variable that is not bound to any scope.

InlinedTD = TypedDict[{'name': T}] # OK, same as the previous type alias, but using the old-style syntax.

It is not possible for an inlined typed dictionary to be extended::

InlinedTD = TypedDict[{'a': int}]
def func():
InlinedTD = TypedDict[{'name': T}] # Not OK: `T` refers to a type variable that is not bound to the scope of `func`.

class SubTD(InlinedTD): # Not allowed
pass

Typing specification changes
----------------------------
Expand Down Expand Up @@ -304,8 +298,8 @@ As inlined typed dictionaries are meant to only support a subset of the
existing syntax, adding this extension mechanism isn't compelling
enough to be supported, considering the added complexity.

If intersections were to be added into the type system, it would most
likely cover this use case.
If intersections were to be added into the type system, it could cover this
use case.


Open Issues
Expand All @@ -328,6 +322,23 @@ implementation to provide the introspection attributes (such as
:attr:`~typing.TypedDict.__total__`), and tools relying on runtime
introspection would have to add proper support for this new type.

Depending on the outcome of the runtime implementation, we can more or less
easily allow extending inlined typed dictionaries::

InlinedTD = TypedDict[{'a': int}]

# If `InlinedTD` is a typing._InlinedTypedDict instance, this adds complexity:
class SubTD(InlinedTD):
pass

Inlined typed dictionaries and extra items
------------------------------------------

:pep:`728` introduces the concept of :ref:`closed <typed-dict-closed>` type
dictionaries. If this PEP were to be accepted, inlined typed dictionaries
will be *closed* by default. This means :pep:`728` needs to be addressed
first, so that this PEP can be updated accordingly.


Copyright
=========
Expand Down

0 comments on commit 764f867

Please sign in to comment.