You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The second case will raise a :exc:`SyntaxWarning` till 3.17.
107
+
Where the first line is the new form of the assert statement that allows
108
+
parentheses and will raise a :exc:`SyntaxWarning` till 3.17..
109
+
The lookahead is needed so statements like ``assert (a, b) <= c, "something"``
110
+
are still parsed correctly and to prevent the parser to eagerly capture the
111
+
tuple as the full statement.
109
112
110
113
Optionally, a new "invalid" grammar rule can be added to the parser to
111
114
promote the current :exc:`SyntaxWarning` to a :exc:`SyntaxError` in the
@@ -147,6 +150,8 @@ with a ``paren_syntax`` flag::
147
150
msg=Constant(value='Error message'),
148
151
paren_syntax=1)])
149
152
153
+
The flag would be removed in 3.18 along with the :exc:`SyntaxWarning`.
154
+
150
155
151
156
Implementing in the compiler
152
157
----------------------------
@@ -175,10 +180,9 @@ On the other hand, assert statements of this kind always pass, so they are
175
180
effectively not doing anything in user code. The authors of this document think
176
181
that this backwards incompatibility nature is beneficial, as it will highlight
177
182
these cases in user code while before they will have passed unnoticed. This case
178
-
has already raised a :exc:`SyntaxWarning` since Python 3.10, therefore these
179
-
cases are expected to be rare, as they require users to ignore existing
180
-
syntax warnings. The continued raising of a :exc:`!SyntaxWarning` should
181
-
mitigate surprises.
183
+
has already raised a :exc:`SyntaxWarning` since Python 3.10, so there has been
184
+
a deprecation period of over 5 years.
185
+
The continued raising of a :exc:`!SyntaxWarning` should mitigate surprises.
182
186
183
187
The change will also result in changes to the AST of ``assert (x,y)``,
184
188
which currently is:
@@ -263,7 +267,7 @@ the case where they appear in parentheses, which already raises a
263
267
:exc:`SyntaxWarning`.
264
268
265
269
The authors of this PEP believe that adding a completely new syntax will,
266
-
first and foremost, not solve the common beginner footgun that this PEP aims to
270
+
first and foremost, not solve the common beginner pitfall that this PEP aims to
267
271
patch, and will not improve the formatting of assert statements across multiple
268
272
lines, which the authors believe the proposed syntax improves.
269
273
@@ -286,6 +290,7 @@ Footnotes
286
290
=========
287
291
288
292
.. [#SO1] `StackOverflow: "'assert' statement with or without parentheses" <https://stackoverflow.com/questions/3112171/assert-statement-with-or-without-parentheses>`_
293
+
.. [#RD] `/r/python: "Rant: use that second expression in assert! " <https://www.reddit.com/r/Python/comments/1n87g91/rant_use_that_second_expression_in_assert/>`_
0 commit comments