Skip to content

PEP 835: Shorthand syntax for Annotated type metadata#4995

Open
till-varoquaux wants to merge 2 commits into
python:mainfrom
till-varoquaux:feature/at-type-annot
Open

PEP 835: Shorthand syntax for Annotated type metadata#4995
till-varoquaux wants to merge 2 commits into
python:mainfrom
till-varoquaux:feature/at-type-annot

Conversation

@till-varoquaux

@till-varoquaux till-varoquaux commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

This PR introduces a draft PEP proposing a shorthand syntax for typing.Annotated using the @ operator (e.g., x: int @ "metadata" instead of typing.Annotated[int, "metadata"]).

This proposal aims to improve the developer ergonomics of metadata-heavy typing frameworks like Pydantic, FastAPI, and SQLModel, aligning Python's type annotations with the conciseness of JVM languages (Java, Kotlin).

All prototype implementations (CPython, Mypy, Pyright, Ruff) are complete and linked in the Reference Implementation section.

Basic requirements (all PEP Types)

  • Read and followed PEP 1 & PEP 12
  • File created from the latest PEP template
  • PEP has next available number, & set in filename (pep-NNNN.rst), PR title (PEP 123: <Title of PEP>) and PEP header
  • Title clearly, accurately and concisely describes the content in 79 characters or less
  • Core dev/PEP editor listed as Author or Sponsor, and formally confirmed their approval
  • Author, Status (Draft), Type and Created headers filled out correctly
  • PEP-Delegate, Topic, Requires and Replaces headers completed if appropriate
  • Required sections included
    • Abstract (first section)
    • Copyright (last section; exact wording from template required)
  • Code is well-formatted (PEP 7/PEP 8) and is in code blocks, with the right lexer names if non-Python
  • PEP builds with no warnings, pre-commit checks pass and content displays as intended in the rendered HTML
  • Authors/sponsor added to .github/CODEOWNERS for the PEP

Standards Track requirements

  • PEP topic discussed in a suitable venue with general agreement that a PEP is appropriate
  • Suggested sections included (unless not applicable)
    • Motivation
    • Specification
    • Rationale
    • Backwards Compatibility
    • Security Implications
    • How to Teach This
    • Reference Implementation
    • Rejected Ideas
    • Open Issues
    • Acknowledgements
    • Footnotes
    • Change History
  • Python-Version set to valid (pre-beta) future Python version, if relevant
  • Any project stated in the PEP as supporting/endorsing/benefiting from the PEP formally confirmed such
  • Right before or after initial merging, PEP discussion thread created and linked to in Discussions-To and Post-History

@till-varoquaux till-varoquaux requested a review from a team as a code owner June 11, 2026 02:52
@till-varoquaux

Copy link
Copy Markdown
Contributor Author

@ilevkivskyi The draft is up and ready for your official sponsorship sign-off whenever you have a moment!

@read-the-docs-community

read-the-docs-community Bot commented Jun 11, 2026

Copy link
Copy Markdown

Documentation build overview

📚 pep-previews | 🛠️ Build #33105185 | 📁 Comparing c237409 against latest (0cc5e08)

  🔍 Preview build  

701 files changed · + 1 added · ± 700 modified

+ Added

± Modified

Comment thread peps/pep-9999.rst Outdated
Comment thread peps/pep-9999.rst Outdated
Comment thread peps/pep-9999.rst Outdated
Comment thread peps/pep-9999.rst Outdated
Comment thread peps/pep-9999.rst
Comment thread peps/pep-9999.rst Outdated
Comment thread peps/pep-9999.rst Outdated

@ilevkivskyi ilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The draft LG! But please take a look at comments by @JelleZijlstra

@till-varoquaux till-varoquaux force-pushed the feature/at-type-annot branch from b646aa7 to c237409 Compare June 12, 2026 03:02
@till-varoquaux

till-varoquaux commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks so much for the review and the help getting this staged, @JelleZijlstra and @ilevkivskyi !

Since my sponsor (@ilevkivskyi) has officially signed off on the draft, could one of the PEP editors go ahead and assign this an official PEP number?

Let me know if there is anything else needed from my end before we can get this merged and move the conversation over to Discourse.

@hugovk hugovk changed the title PEP 9999: Shorthand syntax for Annotated type metadata PEP 835: Shorthand syntax for Annotated type metadata Jun 12, 2026
@hugovk

hugovk commented Jun 12, 2026

Copy link
Copy Markdown
Member

Since my sponsor (@ilevkivskyi) has officially signed off on the draft, could one of the PEP editors go ahead and assign this an official PEP number?

Please use 835.

Comment thread peps/pep-9999.rst
Title: Shorthand syntax for Annotated type metadata (Draft Proposal)
Author: Till Varoquaux <till.varoquaux@gmail.com>
Sponsor: Ivan Levkivskyi <levkivskyi@gmail.com>
Discussions-To: https://discuss.python.org/t/106888

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this old one in the Post-History, the new one will go here.

Comment thread peps/pep-9999.rst
Status: Draft
Type: Standards Track
Topic: Typing
Created: 19-Apr-2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the date the PEP number is assigned.

Suggested change
Created: 19-Apr-2026
Created: 12-Jun-2026

Comment thread peps/pep-9999.rst
Topic: Typing
Created: 19-Apr-2026
Python-Version: 3.16
Post-History: 19-Apr-2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the date of each Discuss topic, with links.

Comment thread peps/pep-9999.rst
@@ -0,0 +1,473 @@
PEP: 9999

@hugovk hugovk Jun 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
PEP: 9999
PEP: 835

I've also added the new PEP checklist to the PR description, please check off the relevant ones, and remember the CODEOWNERS file.

Comment thread peps/pep-9999.rst
@@ -0,0 +1,473 @@
PEP: 9999
Title: Shorthand syntax for Annotated type metadata (Draft Proposal)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Title: Shorthand syntax for Annotated type metadata (Draft Proposal)
Title: Shorthand syntax for Annotated type metadata

Comment thread peps/pep-9999.rst
Comment on lines +28 to +30
that was concise but problematic for type checkers and runtime defaults::

# The older, now discouraged pattern

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you like, you can add red or green sidebars to code blocks to indicate which are "bad"/"discouraged" or "good"/"preferred". See how PEP 8 does it.

For example:

Suggested change
that was concise but problematic for type checkers and runtime defaults::
# The older, now discouraged pattern
that was concise but problematic for type checkers and runtime defaults:
.. code-block::
:class: bad
# The older, now discouraged pattern

Not required, and will leave others for you if you like :)

Comment thread peps/pep-9999.rst

Since its introduction in :pep:`593`, ``Annotated`` has become the standard
mechanism for attaching context-specific metadata to types. It is widely
embraced by libraries such as **Pydantic**, **FastAPI**, and **SQLModel**.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we need bold for these in the abstract and here, at least not the second time.

Suggested change
embraced by libraries such as **Pydantic**, **FastAPI**, and **SQLModel**.
embraced by libraries such as Pydantic, FastAPI, and SQLModel.

Comment thread peps/pep-9999.rst
the language.

This syntax also draws inspiration from other languages with strong metadata
ecosystems, notably Java. In Java (formalized in `JSR 308 <https://jcp.org/en/jsr/detail?id=308>`_)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer anonymous links:

Suggested change
ecosystems, notably Java. In Java (formalized in `JSR 308 <https://jcp.org/en/jsr/detail?id=308>`_)
ecosystems, notably Java. In Java (formalized in `JSR 308 <https://jcp.org/en/jsr/detail?id=308>`__)

Comment thread peps/pep-9999.rst
Comment on lines +105 to +106
and other JVM languages, the ``@`` symbol is standard for type annotations::

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and other JVM languages, the ``@`` symbol is standard for type annotations::
and other JVM languages, the ``@`` symbol is standard for type annotations:
.. code-block:: java

Comment thread peps/pep-9999.rst
Comment on lines +184 to +185
object as ``X @ Y``::

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pycon for Python console

Suggested change
object as ``X @ Y``::
object as ``X @ Y``:
.. code-block:: pycon

Comment thread peps/pep-9999.rst
Comment on lines +199 to +200
The ``repr()`` of an ``AnnotatedType`` uses the shorthand syntax::

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The ``repr()`` of an ``AnnotatedType`` uses the shorthand syntax::
The ``repr()`` of an ``AnnotatedType`` uses the shorthand syntax:
.. code-block:: pycon

Comment thread peps/pep-9999.rst
Comment on lines +208 to +209
origin::

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
origin::
origin:
.. code-block:: pycon

@brianschubert brianschubert added the new-pep A new draft PEP submitted for initial review label Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-pep A new draft PEP submitted for initial review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants