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

Symbol table for comprehensions (list, dict, set) still includes temporary _[1] variable #77017

Closed
mjpieters mannequin opened this issue Feb 12, 2018 · 4 comments
Closed
Labels
3.7 (EOL) end of life 3.8 only security fixes type-bug An unexpected behavior, bug, or error

Comments

@mjpieters
Copy link
Mannequin

mjpieters mannequin commented Feb 12, 2018

BPO 32836
Nosy @mjpieters, @ncoghlan, @nitishch, @miss-islington
PRs
  • bpo-32836: Remove temporary variable usage #5680
  • [3.7] bpo-32836: Remove obsolete code from symtable pass (GH-5680) #5913
  • 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 2018-08-27.09:55:02.075>
    created_at = <Date 2018-02-12.21:33:51.537>
    labels = ['3.8', 'type-bug', '3.7']
    title = 'Symbol table for comprehensions (list, dict, set) still includes temporary _[1] variable'
    updated_at = <Date 2018-08-27.09:55:02.073>
    user = 'https://github.com/mjpieters'

    bugs.python.org fields:

    activity = <Date 2018-08-27.09:55:02.073>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-08-27.09:55:02.075>
    closer = 'serhiy.storchaka'
    components = []
    creation = <Date 2018-02-12.21:33:51.537>
    creator = 'mjpieters'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32836
    keywords = ['patch']
    message_count = 4.0
    messages = ['312081', '312155', '312959', '313565']
    nosy_count = 4.0
    nosy_names = ['mjpieters', 'ncoghlan', 'nitishch', 'miss-islington']
    pr_nums = ['5680', '5913']
    priority = 'normal'
    resolution = None
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue32836'
    versions = ['Python 3.7', 'Python 3.8']

    @mjpieters
    Copy link
    Mannequin Author

    mjpieters mannequin commented Feb 12, 2018

    In Python 2.6, a list comprehension was implemented in the current scope using a temporary _[1] variable to hold the list object:

    >>> import dis
    >>> dis.dis(compile('[x for x in y]', '?', 'exec'))
      1           0 BUILD_LIST               0
                  3 DUP_TOP
                  4 STORE_NAME               0 (_[1])
                  7 LOAD_NAME                1 (y)
                 10 GET_ITER
            >>   11 FOR_ITER                13 (to 27)
                 14 STORE_NAME               2 (x)
                 17 LOAD_NAME                0 (_[1])
                 20 LOAD_NAME                2 (x)
                 23 LIST_APPEND
                 24 JUMP_ABSOLUTE           11
            >>   27 DELETE_NAME              0 (_[1])
                 30 POP_TOP
                 31 LOAD_CONST               0 (None)
                 34 RETURN_VALUE

    Nick Cochlan moved comprehensions into a separate scope in bpo-1660500, and removed the need for a temporary variable in the process (the list / dict / set lives only on the stack).

    However, the symbol table generates the _[1] name:

    >>> import symtable
    >>> symtable.symtable('[x for x in y]', '?', 'exec').get_children()[0].get_symbols()
    [<symbol '.0'>, <symbol '_[1]'>, <symbol 'x'>]

    Can this be dropped? I think all temporary variable handling can be ripped out.

    @ncoghlan
    Copy link
    Contributor

    We still need to the ".0" style temporary variables that are used for argument names in the implicitly generated functions, but it's definitely plausible that we're not actually using the "_[1]" style hidden variables anywhere anymore.

    @ncoghlan ncoghlan added the type-bug An unexpected behavior, bug, or error label Feb 14, 2018
    @ncoghlan
    Copy link
    Contributor

    New changeset 3a087be by Nick Coghlan (Nitish Chandra) in branch 'master':
    bpo-32836: Remove obsolete code from symtable pass (GH-5680)
    3a087be

    @miss-islington
    Copy link
    Contributor

    New changeset 5506d60 by Miss Islington (bot) in branch '3.7':
    bpo-32836: Remove obsolete code from symtable pass (GH-5680)
    5506d60

    @serhiy-storchaka serhiy-storchaka added 3.7 (EOL) end of life 3.8 only security fixes labels Aug 27, 2018
    @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 3.8 only security fixes type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants