Skip to content

Always require parentheses for genexps in base class lists #76204

Closed

Description

@ncoghlan
BPO 32023
Nosy @ncoghlan, @serhiy-storchaka
PRs
  • bpo-32023: Disallow genexprs without parenthesis in class definitions. #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 = 'https://github.com/ncoghlan'

    bugs.python.org 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 = 'https://bugs.python.org/issue32023'
    versions = ['Python 3.7']

    Activity

    1. ncoghlan commented on Nov 14, 2017

      @ncoghlan
      ContributorAuthor

      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

    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      type-bugAn unexpected behavior, bug, or error
      on Nov 14, 2017
    3. serhiy-storchaka commented on Nov 15, 2017

      @serhiy-storchaka
      Member

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

    4. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions