-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
PEP 821: Support for unpacking TypedDicts in Callable type hints #4764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Hello, PEPs need a sponsor before opening and assigning a PEP number. Please can you find a core dev sponsor via the discussion thread, and we can re-open then? See https://peps.python.org/pep-0001/#submitting-a-pep Thanks. |
|
I can sponsor this PEP. I think PEP 821 is taken by now but @Daraan if you renumber it to the latest available number, we can merge it. |
|
823 is next, please update the files to use this. |
|
Actually, 821 isn't used, please keep it :) |
hugovk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also wrap to ~80 columns.
| peps/pep-0815.rst @emmatyping | ||
| peps/pep-0816.rst @brettcannon | ||
| # ... | ||
| peps/pep-0821.rst @Daraan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CODEOWNERS can only list those with write permission, so put Jelle here:
| peps/pep-0821.rst @Daraan | |
| peps/pep-0821.rst @JelleZijlstra |
| Status: Draft | ||
| Type: Standards Track | ||
| Topic: Typing | ||
| Created: 30-Dec-2025 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Date of PEP number assingment:
| Created: 30-Dec-2025 | |
| Created: 12-Jan-2026 |
| Motivation | ||
| ========== | ||
|
|
||
| The typing specification states: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can link to the spec using intersphinx, something like:
| The typing specification states: | |
| The `typing specification <typing:callable>` states: |
| — https://typing.python.org/en/latest/spec/callables.html#callable | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| — https://typing.python.org/en/latest/spec/callables.html#callable |
| — https://typing.python.org/en/latest/spec/callables.html#callable | ||
|
|
||
| This limitation makes it cumbersome to declare callables meant to be invoked | ||
| with keyword arguments. The existing solution is to define a Protocol:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| with keyword arguments. The existing solution is to define a Protocol:: | |
| with keyword arguments. The existing solution is to define a ``Protocol``:: |
| * ``extra_items`` from PEP 728 is respected: functions accepting additional | ||
| ``**kwargs`` are valid if their annotation is compatible with the declared | ||
| type. | ||
| * If neither ``extra_items`` nor ``closed`` (PEP 728) is specified on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * If neither ``extra_items`` nor ``closed`` (PEP 728) is specified on the | |
| * If neither ``extra_items`` nor ``closed`` (:pep:`728`) is specified on the |
| also accepted positionally); positional-only parameters for those keys are | ||
| rejected. | ||
|
|
||
| .. code-block:: python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, you used :: elsewhere, which defaults to Python, so you could pick one and be consistent.
| m2: IntKwPosCallable = mixed_poskw # Accepted | ||
| m3: IntKwPosCallable = mixed_posonly # Rejected | ||
| Inline TypedDicts (PEP 764): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Inline TypedDicts (PEP 764): | |
| Inline ``TypedDicts`` (:pep:`764`): |
| ======================== | ||
|
|
||
| A prototype exists in mypy: | ||
| https://github.com/python/mypy/pull/16083 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| https://github.com/python/mypy/pull/16083 | |
| `python/mypy#16083 <https://github.com/python/mypy/pull/16083>`__. |
| * :pep:`728` - ``extra_items`` in TypedDict | ||
| * :pep:`764` - Inline TypedDict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * :pep:`728` - ``extra_items`` in TypedDict | |
| * :pep:`764` - Inline TypedDict | |
| * :pep:`728` - ``extra_items`` in ``TypedDict`` | |
| * :pep:`764` - Inline ``TypedDict`` |
Basic requirements (all PEP Types)
pep-NNNN.rst), PR title (PEP 123: <Title of PEP>) andPEPheaderAuthororSponsor, and formally confirmed their approvalAuthor,Status(Draft),TypeandCreatedheaders filled out correctlyPEP-Delegate,Topic,RequiresandReplacesheaders completed if appropriate.github/CODEOWNERSfor the PEPStandards Track requirements
Python-Versionset to valid (pre-beta) future Python version, if relevantDiscussions-ToandPost-History@ Editors and Team - There has been an initial discussion which went off track. I am inclined to open up a new one, or should the old one be continued?
📚 Documentation preview 📚: https://pep-previews--4764.org.readthedocs.build/