diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2018-07-05 08:51:51 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-07-05 08:51:51 +0200 |
commit | bcae60d89690a895c5a44ebf8644dfcc317a1737 (patch) | |
tree | a5663b83e395ff8f6b1a8a30ddb5fe40df9c9f96 | |
parent | 070f58010ba1605b8b9907b7cdf241734874f044 (diff) | |
download | pylint-git-bcae60d89690a895c5a44ebf8644dfcc317a1737.tar.gz |
Emit consider-using-get only if the target is a Name, as this is the pattern we try to detect
Close #2254
-rw-r--r-- | pylint/checkers/refactoring.py | 1 | ||||
-rw-r--r-- | pylint/test/functional/consider_using_get.py | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/pylint/checkers/refactoring.py b/pylint/checkers/refactoring.py index c7d6bfc62..c90312bd1 100644 --- a/pylint/checkers/refactoring.py +++ b/pylint/checkers/refactoring.py @@ -391,6 +391,7 @@ class RefactoringChecker(checkers.BaseTokenChecker): and type_and_name_are_equal(node.body[0].value.value, node.test.ops[0][1]) and type_and_name_are_equal(node.body[0].value.slice.value, node.test.left) and len(node.body[0].targets) == 1 + and isinstance(node.body[0].targets[0], astroid.AssignName) and isinstance(utils.safe_infer(node.test.ops[0][1]), astroid.Dict)) if if_block_ok and not node.orelse: diff --git a/pylint/test/functional/consider_using_get.py b/pylint/test/functional/consider_using_get.py index 47a7b47de..15599634f 100644 --- a/pylint/test/functional/consider_using_get.py +++ b/pylint/test/functional/consider_using_get.py @@ -78,3 +78,10 @@ if bool(key) and 'key' in dictionary: # not a simple compare variable = dictionary['key1'] else: variable = 'default' + + +d1 = {'foo': None} +d2 = {} +# Cannot be represented as using .get() +if 'foo' in d1: + d2['bar'] = d1['foo'] |