From b48114d8c5e393d887b879225d1a39e9d18bb531 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 24 Sep 2024 11:40:44 -0700 Subject: [PATCH 1/2] PEP 749: Use __format__ instead of .format as param name --- peps/pep-0749.rst | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/peps/pep-0749.rst b/peps/pep-0749.rst index 6503ef832f1..29ad5ffc00d 100644 --- a/peps/pep-0749.rst +++ b/peps/pep-0749.rst @@ -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. From 1bf37c019781eb6471a6e20c87d73b1b3263fd6d Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 25 Sep 2024 21:17:30 -0700 Subject: [PATCH 2/2] Update peps/pep-0749.rst Co-authored-by: Carol Willing --- peps/pep-0749.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/peps/pep-0749.rst b/peps/pep-0749.rst index 29ad5ffc00d..9b96a9cf8db 100644 --- a/peps/pep-0749.rst +++ b/peps/pep-0749.rst @@ -715,9 +715,9 @@ 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. +leading dot. While ``.format`` has the advantage that it cannot collide with any +identifier, reserved or not, it also prevents ``inspect.signature`` +from creating a signature for annotate functions. The documentation may still use the name ``format`` for simplicity.