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 fgregg
Recipients fgregg
Date 2018-06-16.02:27:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1529116041.48.0.56676864532.issue33874@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-06-16 02:27:21fgreggsetrecipients: + fgregg
2018-06-16 02:27:21fgreggsetmessageid: <1529116041.48.0.56676864532.issue33874@psf.upfronthosting.co.za>
2018-06-16 02:27:21fgregglinkissue33874 messages
2018-06-16 02:27:20fgreggcreate