New submission from Michael Cuthbert <cuthb...@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@python components: Documentation messages: 393704 nosy: docs@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 <rep...@bugs.python.org> <https://bugs.python.org/issue44139> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com