Message319696
Views of dictionary keys and items admit set operations, but the behavior of operations differs significantly from that of set and frozenset.
>>> {}.keys() & []
set()
>>> set() & []
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for &: 'set' and 'list'
>>> set() & []
set()
>>> {}.keys() & frozenset([])
set()
>>> frozenset([]) & {}.keys()
set()
>>> set() & frozenset([])
set()
>>> frozenset([]) & set()
frozenset()
Similar for |, ^, -
>>> [1, 2, 3] - {2:None}.keys()
{1, 3}
Is perhaps particularly surprising
The operators <, <=, >, >= do work as expected.
>>> [1, 2, 3] > {}.keys()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: list() > dict_keys()
I'm not sure if these differences between dictviews and set/frozenset should be considered bugs. If no, it may be good to document that the behavior is different. |
|
Date |
User |
Action |
Args |
2018-06-16 02:27:21 | fgregg | set | recipients:
+ fgregg |
2018-06-16 02:27:21 | fgregg | set | messageid: <1529116041.48.0.56676864532.issue33874@psf.upfronthosting.co.za> |
2018-06-16 02:27:21 | fgregg | link | issue33874 messages |
2018-06-16 02:27:20 | fgregg | create | |
|