[New-bugs-announce] [issue32023] Always require parentheses for genexps in base class lists

Nick Coghlan report at bugs.python.org
Tue Nov 14 05:25:04 EST 2017


New submission from Nick Coghlan <ncoghlan at gmail.com>:

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": 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 [])): pass`

----------
components: Interpreter Core
messages: 306197
nosy: ncoghlan, serhiy.storchaka
priority: low
severity: normal
status: open
title: Always require parentheses for genexps in base class lists
type: behavior
versions: Python 3.7

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


More information about the New-bugs-announce mailing list