[New-bugs-announce] [issue9214] Most Set methods of KeysView and ItemsView do not work right

Daniel Stutzbach report at bugs.python.org
Fri Jul 9 21:31:45 CEST 2010


New submission from Daniel Stutzbach <daniel at stutzbachenterprises.com>:

Attached is a simple Python 3 example script that defines a minimalist MutableMapping that simply wraps a dict, followed by:

x = MySimpleMapping(red=5)
y = x.keys()
z = x.keys() | {'orange'}                                          x['blue'] = 7
print(list(z))
print(list(z))

Output:
['blue', 'red', 'orange']
[]

Expected Output:
['orange', 'red']
['orange', 'red']

The problem is that __or__ ends up returning a new KeysView wrapping a generator instead of returning a set.

To solve the problem, KeysView and ItemsView need to override _from_iterable to return a set instead of a new view.

----------
assignee: stutzbach
components: Library (Lib)
files: keysview_test.py
keywords: easy
messages: 109788
nosy: stutzbach
priority: normal
severity: normal
stage: unit test needed
status: open
title: Most Set methods of KeysView and ItemsView do not work right
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2
Added file: http://bugs.python.org/file17923/keysview_test.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9214>
_______________________________________


More information about the New-bugs-announce mailing list