From f54b22d7a4db26c449d8c446d28f5c2723e77dd4 Mon Sep 17 00:00:00 2001
From: Pang Yu Shao
Date: Tue, 11 May 2021 19:59:55 +0800
Subject: [PATCH] Cleaned up logic based on PR review
---
pylint/checkers/refactoring/recommendation_checker.py | 4 ----
pylint/checkers/utils.py | 11 +++++------
2 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/pylint/checkers/refactoring/recommendation_checker.py b/pylint/checkers/refactoring/recommendation_checker.py
index 2be19e4f5e..920842890e 100644
--- a/pylint/checkers/refactoring/recommendation_checker.py
+++ b/pylint/checkers/refactoring/recommendation_checker.py
@@ -155,8 +155,6 @@ def _check_consider_using_dict_items(self, node: astroid.For) -> None:
continue
value = subscript.slice
- if isinstance(value, astroid.Index):
- value = value.value
if (
not isinstance(value, astroid.Name)
or value.name != node.target.name
@@ -198,8 +196,6 @@ def visit_comprehension(self, node: astroid.Comprehension) -> None:
continue
value = subscript.slice
- if isinstance(value, astroid.Index):
- value = value.value
if (
not isinstance(value, astroid.Name)
or value.name != node.target.name
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index 64fa300ae8..acaff104ac 100644
--- a/pylint/checkers/utils.py
+++ b/pylint/checkers/utils.py
@@ -1504,12 +1504,11 @@ def get_iterating_dictionary_name(
or a dictionary itself, this returns None.
"""
# Is it a proper keys call?
- if isinstance(node.iter, astroid.Call):
- if (
- isinstance(node.iter.func, astroid.Name)
- or node.iter.func.attrname != "keys"
- ):
- return None
+ if (
+ isinstance(node.iter, astroid.Call)
+ and isinstance(node.iter.func, astroid.Attribute)
+ and node.iter.func.attrname == "keys"
+ ):
inferred = safe_infer(node.iter.func)
if not isinstance(inferred, (astroid.BoundMethod, astroid.Dict)):
return None