New submission from Daniel Stutzbach <dan...@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue9214>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to