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 dictviews to 2.7 #46259

Closed
Yhg1s opened this issue Jan 29, 2008 · 11 comments
Closed

Backport dictviews to 2.7 #46259

Yhg1s opened this issue Jan 29, 2008 · 11 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@Yhg1s
Copy link
Member

Yhg1s commented Jan 29, 2008

BPO 1967
Nosy @Yhg1s, @avassalotti, @benjaminp, @ezio-melotti, @graingert
PRs
  • [2.7] bpo-1967: proxy dictviews in dictproxy #15143
  • Files
  • dictviews_backport.diff
  • backport_dictviews.diff
  • 2to3_fixer_dictviews.diff
  • backport_dictviews-2.diff
  • backport_dictviews-3.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.23:17:53.498>
    created_at = <Date 2008-01-29.22:39:04.556>
    labels = ['interpreter-core', 'type-feature']
    title = 'Backport dictviews to 2.7'
    updated_at = <Date 2019-08-06.13:24:16.339>
    user = 'https://github.com/Yhg1s'

    bugs.python.org fields:

    activity = <Date 2019-08-06.13:24:16.339>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-01-11.23:17:53.498>
    closer = 'alexandre.vassalotti'
    components = ['Interpreter Core']
    creation = <Date 2008-01-29.22:39:04.556>
    creator = 'twouters'
    dependencies = []
    files = ['9336', '14651', '14652', '15705', '15706']
    hgrepos = []
    issue_num = 1967
    keywords = ['patch', 'needs review']
    message_count = 11.0
    messages = ['61834', '61881', '70359', '91285', '91286', '96258', '96276', '97066', '97070', '97613', '349107']
    nosy_count = 5.0
    nosy_names = ['twouters', 'alexandre.vassalotti', 'benjamin.peterson', 'ezio.melotti', 'graingert']
    pr_nums = ['15143']
    priority = 'critical'
    resolution = 'accepted'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue1967'
    versions = ['Python 2.7']

    @Yhg1s
    Copy link
    Member Author

    Yhg1s commented Jan 29, 2008

    Patch to backport dictviews to trunk. Consists of some trickery:

    • new 'viewkeys', 'viewvalues' and 'viewitems' methods of dicts,
      returning exactly what 'keys', 'values' and 'items' return in 3.0: three
      new types defined in dictobject.c
    • a future import (dictviews) that changes which opcodes are generated
      for (some) attribute access
    • special opcodes for getting and setting 'keys', 'values' and 'items'
      attributes from an object. These opcodes do nothing special unless a
      future import is in effect in the calling code block *and* the type they
      are called on is a dict subclass, in which case they translate 'keys',
      'values' and 'items' to 'viewkeys', 'viewvalues' and 'viewitems'.
    • similar specialcasing in getattr() and setattr()

    @Yhg1s Yhg1s added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jan 29, 2008
    @tiran tiran added the type-feature A feature request or enhancement label Jan 30, 2008
    @Yhg1s
    Copy link
    Member Author

    Yhg1s commented Jan 31, 2008

    After talking to Guido, got rid of the future import magic in favour of
    just providing 'viewkeys', 'viewitems' and 'viewvalues' methods of
    dicts. This makes efficient 2.6-and-3.0 dict-using code possibly by
    making 2to3 translate the view-methods directly to keys/values/items in
    3.0, and not wrapping everything in list().

    @benjaminp
    Copy link
    Contributor

    I'm going to defer this to 2.7.

    @benjaminp benjaminp changed the title Backport dictviews to 2.6 Backport dictviews to 2.7 Aug 21, 2008
    @avassalotti
    Copy link
    Member

    I have refreshed Thomas's patch to reflect recent updates to dictviews.
    I also added the documentation for dictviews.

    @avassalotti
    Copy link
    Member

    Here is a patch for 2to3 to support the translation of code using dictviews.

    @avassalotti
    Copy link
    Member

    Can someone review the patches? I would like to commit this later this week.

    @ezio-melotti
    Copy link
    Member

    The patch (backport_dictviews.diff) doesn't seem to work for me. I
    applied it on trunk after a svn up, did "./configure && make" and when I
    tried d.view{items|keys|values} Python segfaulted:

    Python 2.7a1+ (trunk:76759M, Dec 12 2009, 00:28:52)
    [GCC 4.4.1] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> d = dict(a=3, b=5)
    >>> d.viewitems()
    Segmentation fault

    I'm tested it on Ubuntu 9.10.

    The docstrings of the three methods are also wrong:

    +PyDoc_STRVAR(viewkeys__doc__,
    + "D.keys() -> a set-like object providing a view on D's keys");

    This should be "D.viewkeys() -> ...", same with the other two.

    @avassalotti
    Copy link
    Member

    It looks like that crash is caused by some bug in the implementation of
    PyUnicode_FromFormat(). I rewrote my patch to avoid it and added some
    additional unit tests.

    @avassalotti
    Copy link
    Member

    The tests were missing in my last patch. So, here's a new one.

    @avassalotti
    Copy link
    Member

    Committed in r77428. Thanks for your comments!

    @graingert
    Copy link
    Mannequin

    graingert mannequin commented Aug 6, 2019

    It seems that 'viewkeys', 'viewvalues' and 'viewitems' methods were not added to types.DictProxyType, was that intentional?

    @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-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants