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.

Author yahya-abou-imran
Recipients yahya-abou-imran
Date 2017-12-29.22:19:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1514585970.62.0.213398074469.issue32449@psf.upfronthosting.co.za>
In-reply-to
Content
Quoting my own post on python-ideas:

After I generate an UML diagram from collections.abc, I found very strange that MappingView inherit from Sized instead of Collection (new in python 3.6).

Yes, MappingView only define __len__ and not __iter__ and __contains__, but all of its subclasses define them (KeysView, ValuesView and ItemViews).

I tried to run the tests in test/test_collections.py after making this change and on only one fail :

Traceback (most recent call last):
  File "/usr/lib/python3.6/test/test_collections.py", line 789, in test_Collection
    self.assertNotIsInstance(x, Collection)
AssertionError: dict_values([]) is an instance of <class 'collections.abc.Collection'>

Wich is absolutely wrong, since in reality a dict_values instance has the behaviour of a Collection:

>>> vals = {1:'a', 2: 'b'}.values()
>>> 'a' in vals
True
>>> 'c' in vals
False
>>> len(vals)
2
>>> for val in vals:
...     print(val)
...    
a
b

The only lack is that it doesn't define a __contains__ method:

>>> '__contains__' in vals
False

It uses __iter__ to find the presence of the value.

But, hey: we have register() for this cases! In fact, when MappingView inherit from Collection, dict_values is considered as a subclass of Collection since it's in the register of ValuesView, causing the above bug...
So, the test have to be changed, and dict_values must be placed in the samples that pass the test, and not in the ones that fail it.

Here is a patch file for this.

The only problem in this is that the MappingView won't be instatiable anymore because of the lack of __contains__ and __iter__.

But since - if my understanding is correct - it's just an "utilty" super class for three other views (so is Collection for Set, Mapping and Sequence), it's not a big deal IMHO.
History
Date User Action Args
2017-12-29 22:19:30yahya-abou-imransetrecipients: + yahya-abou-imran
2017-12-29 22:19:30yahya-abou-imransetmessageid: <1514585970.62.0.213398074469.issue32449@psf.upfronthosting.co.za>
2017-12-29 22:19:30yahya-abou-imranlinkissue32449 messages
2017-12-29 22:19:30yahya-abou-imrancreate