Navigation Menu

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

Backport set and dict comprehensions #46586

Closed
brettcannon opened this issue Mar 17, 2008 · 11 comments
Closed

Backport set and dict comprehensions #46586

brettcannon opened this issue Mar 17, 2008 · 11 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@brettcannon
Copy link
Member

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

    @brettcannon
    Copy link
    Member Author

    Dict comprehensions need to be backported.

    @brettcannon brettcannon added release-blocker interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error and removed release-blocker labels Mar 17, 2008
    @avassalotti
    Copy link
    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.

    @avassalotti avassalotti changed the title Backport dict comprehensions Backport set and dict comprehensions Aug 5, 2009
    @mdickinson
    Copy link
    Member

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

    @avassalotti
    Copy link
    Member

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

    @mdickinson
    Copy link
    Member

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

    @avassalotti
    Copy link
    Member

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

    @avassalotti
    Copy link
    Member

    Committed in r77422.

    @metal
    Copy link
    Mannequin

    metal mannequin commented Aug 4, 2010

    How about fixing set.__repr__ ?

    @fossilet
    Copy link
    Mannequin

    fossilet mannequin commented Nov 14, 2012

    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.

    @ezio-melotti
    Copy link
    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?

    @fossilet
    Copy link
    Mannequin

    fossilet mannequin commented Nov 14, 2012

    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.

    @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

    4 participants