Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP 749: Use __format__ instead of .format as param name #3993

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down
Loading