
On Wed, Jul 01, 2020 at 06:07:40PM +0200, Dominik Vilsmeier wrote:
Because of the set behavior, it will be possible to check whether two dicts have the same keys by simply testing: if a.keys() == b.keys(): ...
which makes perfectly sense. But then, immediately after that, it mentions:
and similarly for .items().
So this means we can do `a.items() == b.items()`. But wait, if the dicts' items are equal, aren't just the dicts themselves equal? So why not just compare `a == b`? Why would I want to compare `a.items() == b.items()`?
Because you might not have access to `a` and `b`, but only the views. Views are first-class objects. You can bind them to variables, pass them to functions, put them in lists etc. So if you ever get passed two dict views for some reason, equality works. Regarding your observation that dict views behave poorly if they have unhashable values, I agree, it is both odd and makes them less useful. Possibly at some point between the PEP and the release of the feature something changed, or perhaps it's just an oversight. -- Steven