summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2018-06-20 09:06:51 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2018-07-24 10:58:19 +0200
commit1626966082a47dee16bbc0e4645b626df28569f9 (patch)
treee8aaa3ece2702f395eee067ad070997d10057a01
parent32fd3b9fb937141f38370fdb5160eb1ce27da135 (diff)
downloadpylint-git-1626966082a47dee16bbc0e4645b626df28569f9.tar.gz
[].extend and similar builtin operations don't emit `dict-*-not-iterating` with the Python 3 porting checker
Close #2187
-rw-r--r--ChangeLog4
-rw-r--r--pylint/checkers/python3.py13
-rw-r--r--pylint/test/unittest_checker_python3.py3
3 files changed, 20 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 27a01eb65..2c19bff86 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -23,6 +23,10 @@ Release date: |TBA|
Close #2042
+ * [].extend and similar builtin operations don't emit `dict-*-not-iterating` with the Python 3 porting checker
+
+ Close #2187
+
What's New in Pylint 1.9.2?
===========================
diff --git a/pylint/checkers/python3.py b/pylint/checkers/python3.py
index 07052860c..7f04c182c 100644
--- a/pylint/checkers/python3.py
+++ b/pylint/checkers/python3.py
@@ -80,6 +80,11 @@ def _is_builtin(node):
_ACCEPTS_ITERATOR = {'iter', 'list', 'tuple', 'sorted', 'set', 'sum', 'any',
'all', 'enumerate', 'dict', 'filter', 'reversed',
'max', 'min'}
+_BUILTIN_METHOD_ACCEPTS_ITERATOR = {
+ 'builtins.list.extend',
+ 'builtins.dict.update',
+ 'builtins.set.update',
+}
DICT_METHODS = {'items', 'keys', 'values'}
@@ -109,6 +114,14 @@ def _in_iterating_context(node):
elif isinstance(parent.func, astroid.Attribute):
if parent.func.attrname == 'join':
return True
+ try:
+ inferred = next(parent.func.infer())
+ except astroid.InferenceError:
+ pass
+ else:
+ if inferred is not astroid.Uninferable:
+ if inferred.qname() in _BUILTIN_METHOD_ACCEPTS_ITERATOR:
+ return True
# If the call is in an unpacking, there's no need to warn,
# since it can be considered iterating.
elif (isinstance(parent, astroid.Assign) and
diff --git a/pylint/test/unittest_checker_python3.py b/pylint/test/unittest_checker_python3.py
index ccf1293ea..ee0db32d2 100644
--- a/pylint/test/unittest_checker_python3.py
+++ b/pylint/test/unittest_checker_python3.py
@@ -208,6 +208,9 @@ class TestPython3Checker(testutils.CheckerTestCase):
'max({}())',
'min({}())',
'3 in {}()',
+ 'set().update({}())',
+ '[].extend({}())',
+ '{{}}.update({}())',
]
non_iterating_code = [
'x = __({}())',