New submission from Forest <[email protected]>:
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.
----------
components: Library (Lib)
messages: 319696
nosy: fgregg
priority: normal
severity: normal
status: open
title: dictviews set operations do not follow pattern of set or frozenset
versions: Python 3.8
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue33874>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com