Closed
Description
Unlike sets, set-like dict view objects behave identical with both operator and non-operator versions of set operations.
In case of sets only non-operator versions accept any iterable as an argument, and one has to explicitly convert iterable to set to use operator on it. That's documented and tested.
s = {"a", "b"}
s.union(["a", "c"]) # valid
s | ["a", "c"] # raises TypeError
Set-like dict view objects, however, accept any iterable after an operator.
d = {"a": "A", "b": "B"}
d.keys() | ["a", "c"] # valid
d.items() | [("c", "C")] # valid
As far as we were able to find that difference in behavior is not documented but is tested for keys but not for items. It's also reflected in the typeshed stubs.
Metadata
Metadata
Assignees
Labels
No labels