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
{{ message }}
Repository navigation
Always require parentheses for genexps in base class lists #76204
bpo-32012: Disallow ambiguous syntax f(x for x in [1],)
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2017-11-15.15:54:47.629>created_at=<Date2017-11-14.10:25:03.999>labels= ['interpreter-core', 'type-bug', '3.7']
title='Always require parentheses for genexps in base class lists'updated_at=<Date2017-11-15.15:54:47.628>user='https://github.com/ncoghlan'
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
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
New changeset ddbce13 by Serhiy Storchaka in branch 'master': bpo-32023: Disallow genexprs without parenthesis in class definitions. (bpo-4400) ddbce13
Activity
ncoghlan commentedon Nov 14, 2017
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' instancesThe language reference states that the parentheses around a generator expression are only optional for "calls with only one argument": https://docs.python.org/3/reference/expressions.html#generator-expressions
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 [])): passserhiy-storchaka commentedon Nov 15, 2017
New changeset ddbce13 by Serhiy Storchaka in branch 'master':
bpo-32023: Disallow genexprs without parenthesis in class definitions. (bpo-4400)
ddbce13