Skip to content

Mypy doesn't catch unhashable literals in hashdependant literals. #8150

Closed
@mental32

Description

@mental32

context on the python-dev mailing list

As per Guido and Nicks suggestions I am opening this issue here :D

"""foo bar."""

from typing import Set, Dict

SOME = {{0}}
print(SOME)


def green_eggs() -> Set[Set[int]]:
    """foo."""
    return {{1}}


def and_ham() -> Dict[Set[int], int]:
    """bar."""
    return {{1}: 0}

Mypy reports this as fine with no errors.
It should detect and throw when encountering {{1}: 0} or Dict[Set[int], int] or {{1}} or {[1]} since these are literals whose types are not hashable therefore they may not be used in types that require members be hashable i.e. Dict or Set.

I'm using mypy 0.750 and Python 3.8.0 (default, Oct 23 2019, 18:51:26) [GCC 9.2.0] on linux

If needed I'm happy to attempt to PR this myself :)

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