Skip to content

Commit fa618cb

Browse files
Fix false positive for unhashable-member when subclassing dict. (#7757)
Closes #7501 Co-authored-by: Pierre Sassoulas <[email protected]>
1 parent 19c205d commit fa618cb

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix false positive for ``unhashable-member`` when subclassing ``dict`` and using the subclass as a dictionary key.
2+
3+
Closes #7501

pylint/checkers/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ def is_hashable(node: nodes.NodeNG) -> bool:
19551955
"""
19561956
try:
19571957
for inferred in node.infer():
1958-
if inferred is astroid.Uninferable:
1958+
if inferred is astroid.Uninferable or isinstance(inferred, nodes.ClassDef):
19591959
return True
19601960
if not hasattr(inferred, "igetattr"):
19611961
return True

tests/functional/u/unhashable_member.py

+6
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ class Unhashable:
2222
{"tomato": "tomahto"}
2323
{dict: {}}
2424
{lambda x: x: "tomato"} # pylint: disable=unnecessary-lambda
25+
26+
27+
class FromDict(dict):
28+
...
29+
30+
{FromDict: 1}

0 commit comments

Comments
 (0)