From 42422b833df7459f2ab2cb1f79ae42a439d29153 Mon Sep 17 00:00:00 2001 From: Mark Byrne Date: Sat, 12 Nov 2022 22:47:58 +0100 Subject: [PATCH 1/2] Fix false positive for ``unhashable-member`` when subclassing ``dict``. Closes #7501 --- doc/whatsnew/fragments/7501.false_positive | 3 +++ pylint/checkers/utils.py | 2 +- tests/functional/u/unhashable_member.py | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 doc/whatsnew/fragments/7501.false_positive diff --git a/doc/whatsnew/fragments/7501.false_positive b/doc/whatsnew/fragments/7501.false_positive new file mode 100644 index 0000000000..27f9da40b8 --- /dev/null +++ b/doc/whatsnew/fragments/7501.false_positive @@ -0,0 +1,3 @@ +Fix false positive for ``unhashable-member`` when subclassing ``dict``. + +Closes #7501 diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index ca3d0e362e..0e99b558a9 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -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 diff --git a/tests/functional/u/unhashable_member.py b/tests/functional/u/unhashable_member.py index a9100b9058..c788668c47 100644 --- a/tests/functional/u/unhashable_member.py +++ b/tests/functional/u/unhashable_member.py @@ -22,3 +22,9 @@ class Unhashable: {"tomato": "tomahto"} {dict: {}} {lambda x: x: "tomato"} # pylint: disable=unnecessary-lambda + + +class FromDict(dict): + ... + +{FromDict: 1} From 80ed477eaeaceef5a541ac49ed7415558cb7c764 Mon Sep 17 00:00:00 2001 From: Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com> Date: Mon, 14 Nov 2022 10:10:28 +0100 Subject: [PATCH 2/2] Update doc/whatsnew/fragments/7501.false_positive Co-authored-by: Pierre Sassoulas --- doc/whatsnew/fragments/7501.false_positive | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whatsnew/fragments/7501.false_positive b/doc/whatsnew/fragments/7501.false_positive index 27f9da40b8..0c2d33a075 100644 --- a/doc/whatsnew/fragments/7501.false_positive +++ b/doc/whatsnew/fragments/7501.false_positive @@ -1,3 +1,3 @@ -Fix false positive for ``unhashable-member`` when subclassing ``dict``. +Fix false positive for ``unhashable-member`` when subclassing ``dict`` and using the subclass as a dictionary key. Closes #7501