Skip to content

Detect unhashable elements in a set? #124

@AlexWaygood

Description

@AlexWaygood

In a typeshed PR the other day, a contributor tried to annotate an object with frozenset[list[str]]. It's obviously impossible to have a frozenset of lists, as lists aren't hashable, and so I was surprised that none of the CI checks raised an error.

I'm in two minds about whether adding a check for that here would be a good idea:

  • It would be very difficult for us to reliably detect whether an object is hashable or not
  • Ideally this is something that would be flagged by a type-checker, not a linter
  • BUT it might be difficult for even a type-checker to detect whether or not an object is hashable.
  • AND we could probably fairly easily hardcode a list of common mutable objects that can't be used in sets, frozensets or dict keys. It wouldn't be comprehensive, but it would detect the most common errors.

What do we think? Worth doing?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions