Skip to content

Commit

Permalink
PEP 749: Add note on signature of __annotate__ (#3831)
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra authored Jun 9, 2024
1 parent afb5867 commit 93557b3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions peps/pep-0749.rst
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,24 @@ an instance of a private stringizer class is used instead of ``ForwardRef``.
After evaluation completes, the implementation of the FORWARDREF format
converts these internal objects into ``ForwardRef`` objects.

Signature of ``__annotate__`` functions
---------------------------------------

:pep:`649` specifies the signature of ``__annotate__`` functions as:

``__annotate__(format: int) -> dict``

However, using ``format`` as a parameter name could lead to collisions
if an annotation uses a class named ``format``. The parameter should be
positional-only and have a name that cannot be a legal identifier in order
to avoid this problem.

The current implementation uses the name ``.format`` with a leading
dot, but the exact name should be considered an implementation detail
and cannot be relied upon.

The documentation may still use the name ``format`` for simplicity.

Backwards Compatibility
=======================

Expand Down

0 comments on commit 93557b3

Please sign in to comment.