@@ -12,7 +12,7 @@ Python-Version: 3.11
12
12
Abstract
13
13
========
14
14
15
- This pep proposes to allow parentheses surrounding the two-subject form of
15
+ This PEP proposes to allow parentheses surrounding the two-argument form of
16
16
assert statements. This will cause the interpreter to reinterpret what before
17
17
would have been an assert with a two-element tuple that will always be True
18
18
(``assert (expression, message) ``) to an assert statement with a subject and a
@@ -23,22 +23,21 @@ failure message, equivalent to the statement with the parentheses removed
23
23
Motivation
24
24
==========
25
25
26
- Is a common user mistake when using the form of the assert stamens that includes
27
- the error message to surround it by parentheses. Unfortunately, this mistake
28
- passes undetected as the assert will always pass due the the fact that is
26
+ It is a common user mistake when using the form of the assert statement that includes
27
+ the error message to surround it with parentheses. Unfortunately, this mistake
28
+ passes undetected as the assert will always pass, because it is
29
29
interpreted as an assert statement where the expression is a two-tuple, which
30
30
always has truth-y value.
31
31
32
- The mistake most often happens when extending thing or description beyond a
33
- single line on assert statements as () are the natural way to do that and as it
34
- is with assert being a statement.
32
+ The mistake most often happens when extending the test or description beyond a
33
+ single line, as parentheses are the natural way to do that.
35
34
36
35
This is so common that a ``SyntaxWarning `` is `now emitted by the compiler
37
36
<https://bugs.python.org/issue35029> `_.
38
37
39
38
Additionally, some other statements in the language allow parenthesized forms
40
- in one way or another like ``import `` statements (``from x import (a,b,c) ``), `` del ``
41
- statements (``del (a,b,c) ``).
39
+ in one way or another like ``import `` statements (``from x import (a,b,c) ``) and
40
+ `` del `` statements (``del (a,b,c) ``).
42
41
43
42
Allowing parentheses not only will remove the common mistake but also will allow
44
43
users and auto-formatters to format long assert statements over multiple lines
@@ -65,13 +64,13 @@ the formatting of other grammar constructs::
65
64
"message",
66
65
)
67
66
68
- This change have been originally discussed and proposed in [bpo-46167 ]_.
67
+ This change has been originally discussed and proposed in [bpo-46167 ]_.
69
68
70
69
Rationale
71
70
=========
72
71
73
72
This change can be implemented in the parser or in the compiler. We have
74
- selected implementing this change in the parser because doing in in the compiler
73
+ selected implementing this change in the parser because doing it in the compiler
75
74
will require re-interpreting the AST of an assert statement with a two-tuple::
76
75
77
76
Module(
@@ -94,16 +93,16 @@ as the AST of an assert statement with an expression and a message::
94
93
type_ignores=[])
95
94
96
95
The problem with this approach is that the AST of the first form will
97
- technically be "incorrect" as we already have an specialized form for the AST of
98
- an assert statement with an expression and a message (the second one). This
96
+ technically be "incorrect" as we already have a specialized form for the AST of
97
+ an assert statement with a test and a message (the second one). This
99
98
means that many tools that deal with ASTs will need to be aware of this change
100
99
in semantics, which will be confusing as there is already a correct form that
101
100
better expresses the new meaning.
102
101
103
102
Specification
104
103
=============
105
104
106
- This PEP proposes changing the grammar from the ``assert `` statement to: ::
105
+ This PEP proposes changing the grammar of the ``assert `` statement to: ::
107
106
108
107
| 'assert' '(' expression ',' expression [','] ')' &(NEWLINE | ';')
109
108
| 'assert' a=expression [',' expression ]
@@ -124,11 +123,11 @@ The change is not technically backwards compatible, as parsing ``assert (x,y)``
124
123
is currently interpreted as an assert statement with a 2-tuple as the subject,
125
124
while after this change it will be interpreted as ``assert x,y ``.
126
125
127
- On the other hand, this kind of assert statements are always true so they are
126
+ On the other hand, assert statements of this kind always pass, so they are
128
127
effectively not doing anything in user code. The authors of this document think
129
128
that this backwards incompatibility nature is beneficial, as it will highlight
130
129
these cases in user code while before they will have passed unnoticed (assuming that
131
- these cases still exist is because users are ignoring syntax warnings).
130
+ these cases still exist because users are ignoring syntax warnings).
132
131
133
132
Security Implications
134
133
=====================
0 commit comments