PEP 692: Explicitly describe the change to Unpack.__repr__ behavior (#2798)

Explicitly describe the change to Unpack.__repr__ behavior
This commit is contained in:
Franek Magiera 2022-09-20 21:25:27 +02:00 committed by GitHub
parent b18ca66cb5
commit 8297df43bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 1 deletions

View File

@ -491,7 +491,20 @@ special method on an object it was used on. This means that at runtime,
``def foo(**kwargs: **T): ...`` is equivalent to ``def foo(**kwargs: **T): ...`` is equivalent to
``def foo(**kwargs: type(T).__typing_unpack__(T)): ...``. ``def foo(**kwargs: type(T).__typing_unpack__(T)): ...``.
``TypedDict`` is the only type in the standard library that is expected to ``TypedDict`` is the only type in the standard library that is expected to
implement ``__typing_unpack__``, which should return ``Unpack[self]``. implement ``__typing_unpack__``, which should return ``Unpack[self]``. The
motivation for reusing :pep:`646`'s ``Unpack`` is described in the
:ref:`Backwards Compatibility <pep-692-backwards-compatibility>` section.
It is worth pointing out that currently using ``Unpack`` in the context of
typing is interchangeable with using the asterisk syntax::
>>> Unpack[Movie]
*<class '__main__.Movie'>
Therefore, in order to be compatible with the new usecase, ``Unpack``'s
``repr`` should be changed to simply ``Unpack[T]``.
.. _pep-692-backwards-compatibility:
Backwards Compatibility Backwards Compatibility
----------------------- -----------------------