This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Always require parentheses for genexps in base class lists
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.7
Status: closed Resolution: fixed
Dependencies: 32012 Superseder:
Assigned To: Nosy List: ncoghlan, serhiy.storchaka
Priority: low Keywords: patch

Created on 2017-11-14 10:25 by ncoghlan, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 4400 merged serhiy.storchaka, 2017-11-15 08:53
Messages (2)
msg306197 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2017-11-14 10:25
The compiler currently allows parentheses to be omitted if a generator expression is the sole entry in a base class list:

    >>> class C(x for x in []): pass
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: cannot create 'generator' instances

The language reference states that the parentheses around a generator expression are only optional for "calls with only one argument":

A base class list is not a call, so this should be treated as a syntax error, rather than being handled as equivalent to `class C((x for x in [])): pass`
msg306275 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-11-15 15:39
New changeset ddbce1378644f9d5ad0651e1c9035bd8c6502edc by Serhiy Storchaka in branch 'master':
bpo-32023: Disallow genexprs without parenthesis in class definitions. (#4400)
Date User Action Args
2022-04-11 14:58:54adminsetgithub: 76204
2017-11-15 15:54:47serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-11-15 15:39:39serhiy.storchakasetmessages: + msg306275
2017-11-15 08:53:41serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request4349
2017-11-14 18:44:28serhiy.storchakasetdependencies: + Disallow ambiguous syntax f(x for x in [1],)
2017-11-14 10:25:04ncoghlancreate