Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix false positive for unhashable-member when subclassing dict. #7757

Merged
merged 2 commits into from Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -2012,7 +2012,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}