Skip to content

Commit 5e0be8f

Browse files
PEP 695: Incorporated recent feedback from python-dev. (#2713)
Co-authored-by: Eric Traut <[email protected]>
1 parent 897fd51 commit 5e0be8f

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

pep-0695.rst

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,30 @@ were less clear. Also, this syntax did not interact well with class and
754754
function decorators, which are common in Python. Only one other popular
755755
programming language, C++, uses this approach.
756756

757+
We likewise considered prefix forms that looked like decorators (e.g.,
758+
``@using(S, T)``). This idea was rejected because such forms would be confused
759+
with regular decorators, and they would not compose well with existing
760+
decorators. Furthermore, decorators are logically executed after the statement
761+
they are decorating, so it would be confusing for them to introduce symbols
762+
(type parameters) that are visible within the "decorated" statement, which is
763+
logically executed before the decorator itself.
764+
765+
766+
Angle Brackets
767+
--------------
768+
Many languages that support generics make use of angle brackets. (Refer to
769+
the table at the end of Appendix A for a summary.) We explored the use of
770+
angle brackets for type parameter declarations in Python, but we ultimately
771+
rejected it for two reasons. First, angle brackets are not considered
772+
"paired" by the Python scanner, so end-of-line characters between a ``<``
773+
and ``>`` token are retained. That means any line breaks within a list of
774+
type parameters would require the use of unsightly and cumbersome ``\`` escape
775+
sequences. Second, Python has already established the use of square brackets
776+
for explicit specialization of a generic type (e.g., ``list[int]``). We
777+
concluded that it would be inconsistent and confusing to use angle brackets
778+
for generic declarations but square brackets for explicit specialization. All
779+
other languages that we surveyed were consistent in this regard.
780+
757781

758782
Bounds Syntax
759783
-------------
@@ -1043,7 +1067,7 @@ Rust uses declaration-site variance, and variance of type parameters is
10431067
typically inferred from their usage. In cases where a type parameter is not
10441068
used within a type, variance can be specified explicitly.
10451069

1046-
Rust provides no way to specify a default type argument.
1070+
A default type argument can be specified using the "=" operator.
10471071

10481072
::
10491073

@@ -1149,7 +1173,7 @@ Summary
11491173
+------------+----------+---------+--------+----------+-----------+-----------+
11501174
| Swift | <> | T: X | | | decl | inferred |
11511175
+------------+----------+---------+--------+----------+-----------+-----------+
1152-
| Rust | <> | T: X, | | | decl | inferred, |
1176+
| Rust | <> | T: X, | | = | decl | inferred, |
11531177
| | | where | | | | explicit |
11541178
+------------+----------+---------+--------+----------+-----------+-----------+
11551179
| Kotlin | <> | T: X | | | use, decl | inferred |

0 commit comments

Comments
 (0)