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

Multidimensional comprehensions cannot access class variables except in the first for #74762

Closed
fengyangwang mannequin opened this issue Jun 5, 2017 · 3 comments
Closed
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@fengyangwang
Copy link
Mannequin

fengyangwang mannequin commented Jun 5, 2017

BPO 30577
Superseder
  • bpo-11796: Comprehensions in a class definition mostly cannot access class variable
  • 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-06-06.00:13:57.148>
    created_at = <Date 2017-06-05.23:56:16.901>
    labels = ['interpreter-core', 'type-bug']
    title = 'Multidimensional comprehensions cannot access class variables except in the first for'
    updated_at = <Date 2017-06-06.00:13:57.147>
    user = 'https://bugs.python.org/fengyangwang'

    bugs.python.org fields:

    activity = <Date 2017-06-06.00:13:57.147>
    actor = 'zach.ware'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-06-06.00:13:57.148>
    closer = 'zach.ware'
    components = ['Interpreter Core']
    creation = <Date 2017-06-05.23:56:16.901>
    creator = 'fengyang.wang'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30577
    keywords = []
    message_count = 3.0
    messages = ['295220', '295221', '295223']
    nosy_count = 1.0
    nosy_names = ['fengyang.wang']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '11796'
    type = 'behavior'
    url = 'https://bugs.python.org/issue30577'
    versions = ['Python 3.5']

    @fengyangwang
    Copy link
    Mannequin Author

    fengyangwang mannequin commented Jun 5, 2017

    Reduced reproduction:

    class X:
        r = [1, 2, 3]
        z = [(i, j) for i in [4, 5] for j in r]

    fails with "NameError: name 'r' is not defined". The expected behavior would be for r to be resolved as the r in the class namespace. Note in contrast that

    class Y:
        r = [1, 2, 3]
        z = [(i, j) for j in r for i in [4, 5]]

    does not fail.

    (Version 3.5.2 on Windows)

    @fengyangwang fengyangwang mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Jun 5, 2017
    @fengyangwang
    Copy link
    Mannequin Author

    fengyangwang mannequin commented Jun 5, 2017

    By the way, in Python 2.7 at least, this was working.

    @fengyangwang
    Copy link
    Mannequin Author

    fengyangwang mannequin commented Jun 6, 2017

    It looks like this is a duplicate of http://bugs.python.org/issue11796

    Sorry for the noise.

    @zware zware closed this as completed Jun 6, 2017
    @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
    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

    1 participant