Skip to content

Commit

Permalink
Fix false positive for unhashable-member when subclassing `dict
Browse files Browse the repository at this point in the history
…`. (#7757)

Closes #7501

Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
  • Loading branch information
mbyrnepr2 and Pierre-Sassoulas committed Nov 17, 2022
1 parent 19c205d commit fa618cb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/7501.false_positive
@@ -0,0 +1,3 @@
Fix false positive for ``unhashable-member`` when subclassing ``dict`` and using the subclass as a dictionary key.

Closes #7501
2 changes: 1 addition & 1 deletion pylint/checkers/utils.py
Expand Up @@ -1955,7 +1955,7 @@ def is_hashable(node: nodes.NodeNG) -> bool:
"""
try:
for inferred in node.infer():
if inferred is astroid.Uninferable:
if inferred is astroid.Uninferable or isinstance(inferred, nodes.ClassDef):
return True
if not hasattr(inferred, "igetattr"):
return True
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/u/unhashable_member.py
Expand Up @@ -22,3 +22,9 @@ class Unhashable:
{"tomato": "tomahto"}
{dict: {}}
{lambda x: x: "tomato"} # pylint: disable=unnecessary-lambda


class FromDict(dict):
...

{FromDict: 1}

0 comments on commit fa618cb

Please sign in to comment.