Registry Mirror
Skip to content

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

Closed

Description

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

    Activity

    1. fengyangwang commented on Jun 5, 2017

      fengyangwangmannequin
      MannequinAuthor

      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)

    2. added
      interpreter-core
      type-bug
      on Jun 5, 2017
    3. fengyangwang commented on Jun 5, 2017

      fengyangwangmannequin
      MannequinAuthor

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

    4. fengyangwang commented on Jun 6, 2017

      fengyangwangmannequin
      MannequinAuthor

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

      Sorry for the noise.

    5. 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

      interpreter-coretype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions