Skip to content

Commit

Permalink
Fix unhashable-member crash when lambda used as a dict key (#7454)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored and Pierre-Sassoulas committed Sep 19, 2022
1 parent 5716ad1 commit 9b359ad
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/7453.bugfix
@@ -0,0 +1,3 @@
Fixed a crash in the ``unhashable-member`` checker when using a ``lambda`` as a dict key.

Closes #7453
2 changes: 2 additions & 0 deletions pylint/checkers/utils.py
Expand Up @@ -1942,6 +1942,8 @@ def is_hashable(node: nodes.NodeNG) -> bool:
for inferred in node.infer():
if inferred is astroid.Uninferable:
return True
if not hasattr(inferred, "igetattr"):
return True
hash_fn = next(inferred.igetattr("__hash__"))
if hash_fn.parent is inferred:
return True
Expand Down
1 change: 1 addition & 0 deletions tests/functional/u/unhashable_member.py
Expand Up @@ -21,3 +21,4 @@ class Unhashable:
{[1, 2, 3]} # [unhashable-member]
{"tomato": "tomahto"}
{dict: {}}
{lambda x: x: "tomato"} # pylint: disable=unnecessary-lambda

0 comments on commit 9b359ad

Please sign in to comment.