Skip to content

Commit 8bf274a

Browse files
authored
Small changes to the section about SyntaxErrors in the 3.10 What's New document (GH-25461)
1 parent 6857198 commit 8bf274a

File tree

1 file changed

+70
-58
lines changed

1 file changed

+70
-58
lines changed

Doc/whatsnew/3.10.rst

Lines changed: 70 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -176,90 +176,102 @@ have been incorporated. Some of the most notable ones:
176176
177177
* Missing ``:`` before blocks:
178178
179-
.. code-block:: python
179+
.. code-block:: python
180180
181-
>>> if rocket.position > event_horizon
182-
File "<stdin>", line 1
183-
if rocket.position > event_horizon
184-
^
185-
SyntaxError: expected ':'
181+
>>> if rocket.position > event_horizon
182+
File "<stdin>", line 1
183+
if rocket.position > event_horizon
184+
^
185+
SyntaxError: expected ':'
186186
187+
(Contributed by Pablo Galindo in :issue:`42997`)
187188
188189
* Unparenthesised tuples in comprehensions targets:
189190
190-
.. code-block:: python
191+
.. code-block:: python
191192
192-
>>> {x,y for x,y in range(100)}
193-
File "<stdin>", line 1
194-
{x,y for x,y in range(100)}
195-
^
196-
SyntaxError: did you forget parentheses around the comprehension target?
193+
>>> {x,y for x,y in range(100)}
194+
File "<stdin>", line 1
195+
{x,y for x,y in range(100)}
196+
^
197+
SyntaxError: did you forget parentheses around the comprehension target?
197198
198-
* Missing commas in collection literals:
199+
(Contributed by Pablo Galindo in :issue:`43017`)
199200
200-
.. code-block:: python
201+
* Missing commas in collection literals and between expressions:
202+
203+
.. code-block:: python
201204
202-
>>> items = {
203-
... x: 1,
204-
... y: 2
205-
... z: 3,
206-
File "<stdin>", line 3
207-
y: 2
208-
^
209-
SyntaxError: invalid syntax. Perhaps you forgot a comma?
205+
>>> items = {
206+
... x: 1,
207+
... y: 2
208+
... z: 3,
209+
File "<stdin>", line 3
210+
y: 2
211+
^
212+
SyntaxError: invalid syntax. Perhaps you forgot a comma?
213+
214+
(Contributed by Pablo Galindo in :issue:`43822`)
210215
211216
* Exception groups without parentheses:
212217
213-
.. code-block:: python
218+
.. code-block:: python
214219
215-
>>> try:
216-
... build_dyson_sphere()
217-
... except NotEnoughScienceError, NotEnoughResourcesError:
218-
File "<stdin>", line 3
219-
except NotEnoughScienceError, NotEnoughResourcesError:
220-
^
221-
SyntaxError: exception group must be parenthesized
220+
>>> try:
221+
... build_dyson_sphere()
222+
... except NotEnoughScienceError, NotEnoughResourcesError:
223+
File "<stdin>", line 3
224+
except NotEnoughScienceError, NotEnoughResourcesError:
225+
^
226+
SyntaxError: exception group must be parenthesized
227+
228+
(Contributed by Pablo Galindo in :issue:`43149`)
222229
223230
* Missing ``:`` and values in dictionary literals:
224231
225-
.. code-block:: python
232+
.. code-block:: python
233+
234+
>>> values = {
235+
... x: 1,
236+
... y: 2,
237+
... z:
238+
... }
239+
File "<stdin>", line 4
240+
z:
241+
^
242+
SyntaxError: expression expected after dictionary key and ':'
226243
227-
>>> values = {
228-
... x: 1,
229-
... y: 2,
230-
... z:
231-
... }
232-
File "<stdin>", line 4
233-
z:
234-
^
235-
SyntaxError: expression expected after dictionary key and ':'
236-
237-
>>> values = {x:1, y:2, z w:3}
238-
File "<stdin>", line 1
239-
values = {x:1, y:2, z w:3}
240-
^
241-
SyntaxError: ':' expected after dictionary key
244+
>>> values = {x:1, y:2, z w:3}
245+
File "<stdin>", line 1
246+
values = {x:1, y:2, z w:3}
247+
^
248+
SyntaxError: ':' expected after dictionary key
249+
250+
(Contributed by Pablo Galindo in :issue:`43823`)
242251
243252
* Usage of ``=`` instead of ``==`` in comparisons:
244253
245-
.. code-block:: python
254+
.. code-block:: python
246255
247-
>>> if rocket.position = event_horizon:
248-
File "<stdin>", line 1
249-
if rocket.position = event_horizon:
250-
^
251-
SyntaxError: cannot assign to attribute here. Maybe you meant '==' instead of '='?
256+
>>> if rocket.position = event_horizon:
257+
File "<stdin>", line 1
258+
if rocket.position = event_horizon:
259+
^
260+
SyntaxError: cannot assign to attribute here. Maybe you meant '==' instead of '='?
261+
262+
(Contributed by Pablo Galindo in :issue:`43797`)
252263
253264
* Usage of ``*`` in f-strings:
254265
255-
.. code-block:: python
266+
.. code-block:: python
256267
257-
>>> f"Black holes {*all_black_holes} and revelations"
258-
File "<stdin>", line 1
259-
(*all_black_holes)
260-
^
261-
SyntaxError: f-string: cannot use starred expression here
268+
>>> f"Black holes {*all_black_holes} and revelations"
269+
File "<stdin>", line 1
270+
(*all_black_holes)
271+
^
272+
SyntaxError: f-string: cannot use starred expression here
262273
274+
(Contributed by Pablo Galindo in :issue:`41064`)
263275
264276
AttributeErrors
265277
~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)