Skip to content

Commit 218e2cc

Browse files
authored
PEP 677: Minor wording and formatting fixes. (#2225)
We're getting ready for a final request for comments to python-dev, so I did one more pass through the PEP to catch remaining readability issues (I was especially looking for things easier to see on the actual PEP page with formatting than the rst doc): - found an incorrectly formatted hyperlink - changed some sentences with ambiguous pronouns - broke up a couple of sentences that seemed too long - tweaked a few places where the wording was okay but nonstandard
1 parent 4a0c977 commit 218e2cc

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

pep-0677.rst

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This PEP introduces a concise and friendly syntax for callable types,
1818
supporting the same functionality as ``typing.Callable`` but with an
1919
arrow syntax inspired by the syntax for typed function
2020
signatures. This allows types like ``Callable[[int, str], bool]`` to
21-
be written ``(int, str) -> bool``.
21+
be written as ``(int, str) -> bool``.
2222

2323
The proposed syntax supports all the functionality provided by
2424
``typing.Callable`` and ``typing.Concatenate``, and is intended to
@@ -78,7 +78,7 @@ There are a few usability challenges with ``Callable`` we can see here:
7878
- The bracket structure is not visually similar to how function signatures
7979
are written.
8080
- It requires an explicit import, unlike many of the other most common
81-
types like ``list``.
81+
types like ``list`` and ``dict``.
8282

8383
Possibly as a result, `programmers often fail to write complete
8484
Callable types
@@ -102,8 +102,8 @@ the benefits of static typing. For example, they might write this::
102102
flat_map(add, [1, 2, 3]) # oops, no type check error!
103103

104104
There's some partial type information here - we at least know that ``func``
105-
needs to be callable. But we've dropped too much type information to catch
106-
the mistake.
105+
needs to be callable. But we've dropped too much type information for
106+
type checkers to find the bug.
107107

108108
With our proposal, the example looks like this::
109109

@@ -142,7 +142,7 @@ types, is more complicated to read and write, and still requires an
142142
import and bracket-based syntax.
143143

144144
In this proposal, we chose to support all the existing semantics of
145-
``typing.Callable``, without adding support for new features. We took
145+
``typing.Callable``, without adding support for new features. We made
146146
this decision after examining how frequently each feature might be
147147
used in existing typed and untyped open-source code. We determined
148148
that the vast majority of use cases are covered.
@@ -296,8 +296,8 @@ It also optionally allows adding names to the arguments, for example::
296296

297297
(x: Int, y: String) -> Bool
298298

299-
As in TypeScript, the argument names if provided are just there for documentation
300-
and are not part of the type itself.
299+
As in TypeScript, the argument names (if provided) are just there for
300+
documentation and are not part of the type itself.
301301

302302
Scala
303303
~~~~~
@@ -315,11 +315,11 @@ Function types can optionally include names, for example::
315315

316316
Unlike in TypeScript and Kotlin, these names are part of the type if
317317
provided - any function implementing the type must use the same names.
318-
This is similar to the extended syntax proposal we described in our
318+
This is similar to the extended syntax proposal we describe in our
319319
`Rejected Alternatives`_ section.
320320

321-
Function Definition vs Callable Type Annotations
322-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
321+
Function Definitions vs Callable Type Annotations
322+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
323323

324324
In all of the languages listed above, type annotations for function
325325
definitions use a ``:`` rather than a ``->``. For example, in TypeScript
@@ -542,7 +542,7 @@ Trailing Commas
542542
~~~~~~~~~~~~~~~
543543

544544
- Following the precedent of function signatures, putting a comma in
545-
an empty arguments list is illegal, ``(,) -> bool`` is a syntax
545+
an empty arguments list is illegal: ``(,) -> bool`` is a syntax
546546
error.
547547
- Again following precedent, trailing commas are otherwise always
548548
permitted::
@@ -710,7 +710,7 @@ We decided against proposing it for the following reasons:
710710
demonstrate that fewer than 3% of use cases would benefit from any
711711
of the added features.
712712
- The group that debated these proposals was split down the middle
713-
about whether these changes are even desirable:
713+
about whether these changes are desirable:
714714

715715
- On the one hand, they make callable types more expressive. On the
716716
other hand, they could easily confuse users who have not read the
@@ -723,8 +723,8 @@ We decided against proposing it for the following reasons:
723723
- We intend to implement the current proposal in a way that is
724724
forward-compatible with the more complicated extended syntax. If the
725725
community decides after more experience and discussion that we want
726-
the additional features, they should be straightforward to propose
727-
in the future.
726+
the additional features, it should be straightforward to propose
727+
them in the future.
728728
- Even a full extended syntax cannot replace the use of callback
729729
protocols for overloads. For example, no closed form of callable type
730730
could express a function that maps bools to bools and ints to floats,
@@ -752,7 +752,8 @@ We decided against proposing it for the following reasons:
752752
We confirmed that the current proposal is forward-compatible with
753753
extended syntax by
754754
`implementing <https://github.com/stroxler/cpython/tree/callable-type-syntax--extended>`_
755-
a quick-and-dirty grammar and AST on top of this grammar and AST for.
755+
a grammar and AST for this extended syntax on top of our reference
756+
implementation of this PEP's grammar.
756757

757758

758759
Syntax Closer to Function Signatures
@@ -778,11 +779,10 @@ The benefits of this proposal would have included:
778779

779780
Key downsides that led us to reject the idea include the following:
780781

781-
- A large majority of use cases only use positional-only arguments,
782-
and this syntax would be more verbose for that use case, both
783-
because of requiring argument names and an explicit ``/``, for
784-
example ``(int, /) -> bool`` where our proposal allows ``(int) ->
785-
bool``
782+
- A large majority of use cases only use positional-only arguments. This
783+
syntax would be more verbose for that use case, both because of requiring
784+
argument names and an explicit ``/``, for example ``(int, /) -> bool`` where
785+
our proposal allows ``(int) -> bool``
786786
- The requirement for explicit ``/`` for positional-only arguments has
787787
a high risk of causing frequent bugs - which often would not be
788788
detected by unit tests - where library authors would accidentally
@@ -982,8 +982,7 @@ This actually is a significant readability improvement for
982982
multi-argument functions, but the problem is that it makes callables
983983
with one arguments, which are the most common arity, hard to
984984
write: because ``(x)`` evaluates to ``x``, they would have to be
985-
written like ``callable[(int,), bool]``. This is awkward enough that
986-
we dislike this idea.
985+
written like ``callable[(int,), bool]``. We find this awkward.
987986

988987
Moreover, none of these ideas help as much with reducing verbosity
989988
as the current proposal, nor do they introduce as strong a visual cue
@@ -1078,8 +1077,8 @@ types. However, we have since begun to do so, e.g. with PEP 604.
10781077
at the PyCon Typing Summit 2021.
10791078

10801079
**Steven** `brought up this proposal on typing-sig
1081-
<https://mail.python.org/archives/list/[email protected]/thread/3JNXLYH5VFPBNIVKT6FFBVVFCZO4GFR2>`. We
1082-
had several meetings to discuss alternatives, and `this presentation
1080+
<https://mail.python.org/archives/list/[email protected]/thread/3JNXLYH5VFPBNIVKT6FFBVVFCZO4GFR2>`_.
1081+
We had several meetings to discuss alternatives, and `this presentation
10831082
<https://www.dropbox.com/s/sshgtr4p30cs0vc/Python%20Callable%20Syntax%20Proposals.pdf?dl=0>`_
10841083
led us to the current proposal.
10851084

0 commit comments

Comments
 (0)