[New-bugs-announce] [issue44139] Unparenthesized tuple doc bug in what's new

Michael Cuthbert report at bugs.python.org
Fri May 14 23:57:18 EDT 2021


New submission from Michael Cuthbert <cuthbert at mit.edu>:

The What's New in Python 3.10 docs demonstrates a richer SyntaxError for this set comprehension:

>>> {x,y for x,y in range(100)}
  File "<stdin>", line 1
    {x,y for x,y in range(100)}
     ^
SyntaxError: did you forget parentheses around the comprehension target?


The problem (at least for beginners) is that there are two errors in the line.  Parenthesizing the comprehension target gets "TypeError: cannot unpack non-iterable int object" since "x,y in range(...)" does not work.  I think it would be better to illustrate with code that works if not for the missing parentheses.  Something like this:

>>> {x,y for x,y in zip('abcd', 'efgh')}
  File "<stdin>", line 1
    {x,y for x,y in zip('abcd', 'efgh')}
     ^
SyntaxError: did you forget parentheses around the comprehension target?

Thanks for the great work on making error messages better! This prof. who often has to help students with Python errors heartily approves!

----------
assignee: docs at python
components: Documentation
messages: 393704
nosy: docs at python, mscuthbert
priority: normal
severity: normal
status: open
title: Unparenthesized tuple doc bug in what's new
type: behavior
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44139>
_______________________________________


More information about the New-bugs-announce mailing list