[issue9214] Most Set methods of KeysView and ItemsView do not work right

Raymond Hettinger report at bugs.python.org
Sat Jul 10 01:02:27 CEST 2010


Raymond Hettinger <rhettinger at users.sourceforge.net> added the comment:

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

Thanks for the good analysis and suggested fix.  I believe both are correct and they match the behavior of real dictionaries. 

  def _from_iterable(self, it):
     return set(it)

Proposed tests to match real dicts:

  x = MySimpleMapping()   # from stuzback's example
  x['red'] = 5
  y = x.keys()
  assert isinstance(y, collections.Set)
  assert not isinstance(y, collections.MutableSet)
  z = x.keys() | {'orange'}
  assert type(z) is set

----------
priority: normal -> high

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


More information about the Python-bugs-list mailing list