Message309271
> 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).
That isn't strange at all. MappingView predates Collection, so of course it didn't inherit from collection.
> Yes, MappingView only define __len__ and not __iter__
> and __contains__, but all of its subclasses define them
> (KeysView, ValuesView and ItemViews).
It is irrelevant what extra behaviors subclasses may or may not add. The MappingView ABC is a public API and users are free to use it in other ways (as long as they stick with the publicly document API). For example, the following is allowed (even it seems odd to you):
>>> from collections.abc import MappingView
>>> mv = MappingView(['a', 'b'])
>>> len(mv) # guaranteed
2
>>> repr(mv) # guaranteed
"MappingView(['a', 'b'])"
>>> 'a' in mv # not guaranteed
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
'a' in mv
TypeError: argument of type 'MappingView' is not iterable
>>> list(mv) # not guaranteed
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
list(mv)
TypeError: 'MappingView' object is not iterable |
|
Date |
User |
Action |
Args |
2017-12-31 09:39:38 | rhettinger | set | recipients:
+ rhettinger, r.david.murray, yahya-abou-imran |
2017-12-31 09:39:38 | rhettinger | set | messageid: <1514713178.32.0.467229070634.issue32449@psf.upfronthosting.co.za> |
2017-12-31 09:39:38 | rhettinger | link | issue32449 messages |
2017-12-31 09:39:36 | rhettinger | create | |
|