Skip to content

Assigning an iterator to the type hint collections.abc.Hashable gets error even though an iterator is hashable #20236

@hyperkai

Description

@hyperkai

*Memo:

  • Python 3.14.0
  • mypy 1.18.2
  • mypy test.py
  • Windows 11

An iterator is hashable as shown below:

print(hash(iter([0, 1, 2])))
# 127553071047

But assigning an iterator to the type hint collections.abc.Hashable gets the error as shown below even though an iterator is hashable:

from collections.abc import Hashable

v: Hashable = iter([0, 1, 2])
# Error

error: Incompatible types in assignment (expression has type "Iterator[int]", variable has type "Hashable")

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions