PEP 749: Add note on signature of __annotate__ (#3831)
This commit is contained in:
parent
afb586782c
commit
93557b3808
|
@ -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
|
After evaluation completes, the implementation of the FORWARDREF format
|
||||||
converts these internal objects into ``ForwardRef`` objects.
|
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
|
Backwards Compatibility
|
||||||
=======================
|
=======================
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue