Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Underdocumented and partially untested behavior of set-like dict views #96408

Copy link
Copy link
Closed
@filiplajszczak

Description

@filiplajszczak
Issue body actions

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.