This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Backport dictviews to 2.7
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 2.7
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: alexandre.vassalotti, benjamin.peterson, ezio.melotti, graingert, twouters
Priority: critical Keywords: needs review, patch

Created on 2008-01-29 22:39 by twouters, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
dictviews_backport.diff twouters, 2008-01-31 01:50
backport_dictviews.diff alexandre.vassalotti, 2009-08-04 23:51
2to3_fixer_dictviews.diff alexandre.vassalotti, 2009-08-04 23:53
backport_dictviews-2.diff alexandre.vassalotti, 2009-12-30 23:09
backport_dictviews-3.diff alexandre.vassalotti, 2009-12-30 23:39
Pull Requests
URL Status Linked Edit
PR 15143 closed python-dev, 2019-08-06 13:24
Messages (11)
msg61834 - (view) Author: Thomas Wouters (twouters) * (Python committer) Date: 2008-01-29 22:39
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()
msg61881 - (view) Author: Thomas Wouters (twouters) * (Python committer) Date: 2008-01-31 01:50
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().
msg70359 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-07-28 17:02
I'm going to defer this to 2.7.
msg91285 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2009-08-04 23:51
I have refreshed Thomas's patch to reflect recent updates to dictviews.
I also added the documentation for dictviews.
msg91286 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2009-08-04 23:53
Here is a patch for 2to3 to support the translation of code using dictviews.
msg96258 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2009-12-11 14:17
Can someone review the patches? I would like to commit this later this week.
msg96276 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-12-11 22:59
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:

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

This should be "D.viewkeys() -> ...", same with the other two.
msg97066 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2009-12-30 23:09
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.
msg97070 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2009-12-30 23:39
The tests were missing in my last patch. So, here's a new one.
msg97613 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2010-01-11 23:17
Committed in r77428. Thanks for your comments!
msg349107 - (view) Author: Thomas Grainger (graingert) * Date: 2019-08-06 13:15
It seems that 'viewkeys', 'viewvalues' and 'viewitems' methods were not added to types.DictProxyType, was that intentional?
Date User Action Args
2022-04-11 14:56:30adminsetgithub: 46259
2019-08-06 13:24:16python-devsetpull_requests: + pull_request14880
2019-08-06 13:15:47graingertsetnosy: + graingert
messages: + msg349107
2010-01-11 23:17:53alexandre.vassalottisetstatus: open -> closed
resolution: accepted
messages: + msg97613

stage: patch review -> resolved
2009-12-30 23:39:07alexandre.vassalottisetfiles: + backport_dictviews-3.diff

messages: + msg97070
2009-12-30 23:09:27alexandre.vassalottisetfiles: + backport_dictviews-2.diff

messages: + msg97066
2009-12-11 22:59:29ezio.melottisetkeywords: + needs review, - 26backport
nosy: + ezio.melotti
messages: + msg96276

2009-12-11 14:17:26alexandre.vassalottisetmessages: + msg96258
2009-08-04 23:53:20alexandre.vassalottisetfiles: + 2to3_fixer_dictviews.diff

messages: + msg91286
2009-08-04 23:51:25alexandre.vassalottisetfiles: + backport_dictviews.diff

nosy: + alexandre.vassalotti
messages: + msg91285

stage: patch review
2008-08-21 14:49:12benjamin.petersonsettitle: Backport dictviews to 2.6 -> Backport dictviews to 2.7
versions: + Python 2.7, - Python 2.6
2008-07-28 17:02:50benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg70359
2008-03-29 01:44:12georg.brandlsetkeywords: + 26backport
2008-03-29 01:44:07georg.brandlsetpriority: normal -> critical
2008-01-31 01:50:58twouterssetfiles: + dictviews_backport.diff
messages: + msg61881
2008-01-31 01:50:48twouterssetfiles: - dictviews_backport.diff
2008-01-30 09:54:11christian.heimessetpriority: normal
type: enhancement
2008-01-29 22:39:04twouterscreate