Skip to content

Commit 9922546

Browse files
committed
Mention the limitation of the current "__extra__" approach.
I left out the rewrite to other proposed syntax such as using "OtherFields[]" with an arbitrary key before there is sufficient discussion on the alternatives available to us. Signed-off-by: Zixuan James Li <[email protected]>
1 parent 5634533 commit 9922546

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

peps/pep-0728.rst

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,13 +531,22 @@ checking logic:
531531
achieve this using `total=False`, which follows from existing rules for
532532
expanded callables.
533533

534+
Alternatives to the ``__extra__`` Magic Field
535+
---------------------------------------------
536+
537+
As it was pointed out in the PEP 705 review comment [11]_, ``__extra__``
538+
as a field has some disadvantages, including not allowing "__extra__"
539+
as a regular key, requiring special-handling to disallow ``Required``
540+
and ``NotRequired``. There could be some better alternatives to this
541+
without the above mentioned issues.
542+
534543
Backwards Compatibility
535544
=======================
536545

537-
Dunder attributes like ``__extra__`` are reserved for stdlib, we need not
538-
concerned about using it in this proposal. If the proposal is accepted, neither
539-
``__required_keys__`` and ``__optional_keys__`` should include ``__extra__`` in
540-
runtime.
546+
While dunder attributes like ``__extra__`` are reserved for stdlib, it is still
547+
a limitation that ``__extra__`` is no longer usable as a regular key. If the
548+
proposal is accepted, neither ``__required_keys__`` and ``__optional_keys__``
549+
should include ``__extra__`` in runtime.
541550

542551
Because this is a type-checking feature, it can be made available to older
543552
versions as long as the type checker supports it without requiring imports from
@@ -610,6 +619,7 @@ References
610619
.. [8] https://www.typescriptlang.org/docs/handbook/2/objects.html#index-signatures
611620
.. [9] https://github.com/microsoft/TypeScript/issues/17867
612621
.. [10] https://github.com/python/mypy/pull/15612#discussion_r1298300340
622+
.. [11] https://discuss.python.org/t/pep-705-typeddict-read-only-and-other-keys/36457/6
613623
614624
Acknowledgments
615625
================

0 commit comments

Comments
 (0)