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

dict items views have set like operations even when the values are not hashable. #111622

Copy link
Copy link
Closed
@EvanTheB

Description

@EvanTheB
Issue body actions

Documentation

Keys views are set-like since their entries are unique and :term:hashable. If all values are hashable, so that (key, value) pairs are unique and hashable, then the items view is also set-like. (Values views are not treated as set-like since the entries are generally not unique.) For set-like views, all of the operations defined for the abstract base class :class:collections.abc.Set are available (for example, ==, <, or ^). While using set operators, set-like views accept any iterable as the other operand, unlike sets which only accept sets as the input.

> {1:2, 3:4}.items() >= {1:2}.items()
True
> {1:[2], 3:4}.items() >= {1:[2]}.items()
True
> set({1:[2], 3:4}.items())
TypeError: unhashable type: 'list'

It seems like this documentation is not accurate. dict.items() does have set operations even when the values are not hashable.

See also: https://stackoverflow.com/questions/77399592/set-like-behaviour-of-dict-items-for-non-hashable-values

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirDocumentation in the Doc dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)

    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.