Skip to content

Commit 9b359ad

Browse files
jacobtylerwallsPierre-Sassoulas
authored andcommitted
Fix unhashable-member crash when lambda used as a dict key (#7454)
1 parent 5716ad1 commit 9b359ad

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

doc/whatsnew/fragments/7453.bugfix

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed a crash in the ``unhashable-member`` checker when using a ``lambda`` as a dict key.
2+
3+
Closes #7453

pylint/checkers/utils.py

+2
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,8 @@ def is_hashable(node: nodes.NodeNG) -> bool:
19421942
for inferred in node.infer():
19431943
if inferred is astroid.Uninferable:
19441944
return True
1945+
if not hasattr(inferred, "igetattr"):
1946+
return True
19451947
hash_fn = next(inferred.igetattr("__hash__"))
19461948
if hash_fn.parent is inferred:
19471949
return True

tests/functional/u/unhashable_member.py

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ class Unhashable:
2121
{[1, 2, 3]} # [unhashable-member]
2222
{"tomato": "tomahto"}
2323
{dict: {}}
24+
{lambda x: x: "tomato"} # pylint: disable=unnecessary-lambda

0 commit comments

Comments
 (0)