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

Closed
ncoghlan opened this issue Nov 14, 2017 · 2 comments
Closed

Always require parentheses for genexps in base class lists #76204

ncoghlan opened this issue Nov 14, 2017 · 2 comments
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@ncoghlan
Copy link
Contributor

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']

    @ncoghlan
    Copy link
    Contributor Author

    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

    @ncoghlan ncoghlan added 3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Nov 14, 2017
    @serhiy-storchaka
    Copy link
    Member

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

    @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
    Labels
    3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants