PEP 749: Add note on signature of __annotate__ (#3831)

This commit is contained in:
Jelle Zijlstra 2024-06-09 05:52:48 -06:00 committed by GitHub
parent afb586782c
commit 93557b3808
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 0 deletions

View File

@ -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
=======================