Skip to content

Backport set and dict comprehensions #46586

Description

@brettcannon
BPO 2333
Nosy @brettcannon, @mdickinson, @avassalotti, @ezio-melotti
Dependencies
  • bpo-2335: Backport set literals
  • Files
  • backport_dict_and_set_comprehension.diff
  • patch_failure.log: Output of attempt to apply patch.
  • set_and_dict_comprehensions.diff
  • 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 2010-01-11.22:36:41.905>
    created_at = <Date 2008-03-17.17:37:33.157>
    labels = ['interpreter-core', 'type-bug']
    title = 'Backport set and dict comprehensions'
    updated_at = <Date 2012-11-14.09:00:10.725>
    user = 'https://github.com/brettcannon'

    bugs.python.org fields:

    activity = <Date 2012-11-14.09:00:10.725>
    actor = 'fossilet'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-01-11.22:36:41.905>
    closer = 'alexandre.vassalotti'
    components = ['Interpreter Core']
    creation = <Date 2008-03-17.17:37:33.157>
    creator = 'brett.cannon'
    dependencies = ['2335']
    files = ['14661', '14670', '27981']
    hgrepos = []
    issue_num = 2333
    keywords = ['patch', '26backport']
    message_count = 11.0
    messages = ['63690', '91338', '91367', '91368', '91369', '96257', '97611', '112812', '175539', '175541', '175554']
    nosy_count = 6.0
    nosy_names = ['brett.cannon', 'mark.dickinson', 'fossilet', 'alexandre.vassalotti', 'ezio.melotti', 'metal']
    pr_nums = []
    priority = 'critical'
    resolution = 'accepted'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue2333'
    versions = ['Python 2.7']

    Activity

    1. brettcannon commented on Mar 17, 2008

      @brettcannon
      MemberAuthor

      Dict comprehensions need to be backported.

    2. avassalotti commented on Aug 5, 2009

      @avassalotti
      Member

      Here is a patch to backport dict and set comprehensions to the trunk.

      The patch preserves the Python 3.x's syntax and semantics of the
      feature. Although this makes dict and set comprehensions is inconsistent
      with list comprehension, I believe this is reasonable since the backport
      aimed to improve the compatibility of Python 2.x with Python 3.x.

      The patch also adds support for dict and set comprehensions to the
      'compiler' package. However, the support is quirky and use the list
      comprehension semantics of Python 2.x. This allowed me to keep the patch
      simple and to keep myself sane ;-).

      Finally, the patch changes the name of the following syntax nodes:
      'gen_expr', 'gen_iter', 'gen_if', and 'testlist_gexp'. I don't know if
      we have compatibility requirements for this; so I don't know if this is
      an issue.

    3. changed the title [-]Backport dict comprehensions[/-] [+]Backport set and dict comprehensions[/+] on Aug 5, 2009
    4. mdickinson commented on Aug 6, 2009

      @mdickinson
      Member

      Alexandre, I can't get this to apply cleanly to my svn trunk checkout
      (r74328) (see attached log). Am I doing something stupid?

    5. avassalotti commented on Aug 6, 2009

      @avassalotti
      Member

      You need to apply the set literal patch I posted in bpo-2335 first.

    6. mdickinson commented on Aug 6, 2009

      @mdickinson
      Member

      Ah, that works. Thanks! (I'll pay more attention to the tracker
      Dependencies field in future.)

    7. avassalotti commented on Dec 11, 2009

      @avassalotti
      Member

      If there are no objections, I will commit this patch later this week
      after issue bpo-2335.

    8. avassalotti commented on Jan 11, 2010

      @avassalotti
      Member

      Committed in r77422.

    9. metal commented on Aug 4, 2010

      metalmannequin
      Mannequin

      How about fixing set.__repr__ ?

    10. fossilet commented on Nov 14, 2012

      fossiletmannequin
      Mannequin

      Great they are backported to 2.7. Dictionary and set comprehensions are not documented in the tutorial of 2.7, though they are in the language reference. Is it OK to add these to the tutorial? I've uploaded a patch.

    11. ezio-melotti commented on Nov 14, 2012

      @ezio-melotti
      Member

      Is it OK to add these to the tutorial? I've uploaded a patch.

      Yes, but please create a new issue.

      How about fixing set.__repr__ ?

      Is it broken?

    12. fossilet commented on Nov 14, 2012

      fossiletmannequin
      Mannequin

      I think metal means that the different ways set is repr'd in 2.7 and 3.

      In 2.7:

      In [9]: a = {x for x in 'abracadabra' if x not in 'abc'}

      In [10]: repr(a)
      Out[10]: "set(['r', 'd'])"

      In 3.2:
      In [6]: a = {x for x in 'abracadabra' if x not in 'abc'}

      In [7]: repr(a)
      Out[7]: "{'r', 'd'}"

      We were saying not changing __repr__ in bpo-2335.

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