Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always require parentheses for genexps in base class lists #76204

ncoghlan opened this issue Nov 14, 2017 · 2 comments

Always require parentheses for genexps in base class lists #76204

ncoghlan opened this issue Nov 14, 2017 · 2 comments
3.7 interpreter-core type-bug


Copy link

@ncoghlan ncoghlan commented Nov 14, 2017

BPO 32023
Nosy @ncoghlan, @serhiy-storchaka
  • #4400
  • Dependencies
  • 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 = None
    closed_at = <Date 2017-11-15.15:54:47.629>
    created_at = <Date 2017-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 = <Date 2017-11-15.15:54:47.628>
    user = '' fields:

    activity = <Date 2017-11-15.15:54:47.628>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-11-15.15:54:47.629>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2017-11-14.10:25:03.999>
    creator = 'ncoghlan'
    dependencies = ['32012']
    files = []
    hgrepos = []
    issue_num = 32023
    keywords = ['patch']
    message_count = 2.0
    messages = ['306197', '306275']
    nosy_count = 2.0
    nosy_names = ['ncoghlan', 'serhiy.storchaka']
    pr_nums = ['4400']
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = ''
    versions = ['Python 3.7']

    Copy link
    Contributor Author

    @ncoghlan ncoghlan commented 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' 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

    @ncoghlan ncoghlan added 3.7 interpreter-core type-bug labels Nov 14, 2017
    Copy link

    @serhiy-storchaka serhiy-storchaka commented Nov 15, 2017

    New changeset ddbce13 by Serhiy Storchaka in branch 'master':
    bpo-32023: Disallow genexprs without parenthesis in class definitions. (bpo-4400)

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    3.7 interpreter-core type-bug
    None yet

    No branches or pull requests

    2 participants