Skip to content

Commit

Permalink
PEP 749: Use __format__ instead of .format as param name
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Sep 24, 2024
1 parent 680c8b1 commit b48114d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions peps/pep-0749.rst
Original file line number Diff line number Diff line change
Expand Up @@ -710,12 +710,14 @@ Signature of ``__annotate__`` functions

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.
positional-only and have a name that does not coincide with an
identifier used by user code. We propose to use the name ``__format__``,
as names with double underscores are reserved for the Python implementation.

A previous version of this PEP proposed using the name ``.format`` with a
leading dot. This has the advantage that it cannot collide with any
identifier, reserved or not, but it also made it so ``inspect.signature``
could not create a signature for annotate functions.

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

Expand Down

0 comments on commit b48114d

Please sign in to comment.