summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2015-02-21 21:27:17 +0200
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2015-02-21 21:27:17 +0200
commit062999db0385f9f3f31df47f1ddbf84271ad0ab8 (patch)
tree8c7b3e7b35a8c206122890718f158116176ae9e3
parentcbc81d3cc95b61206669c0a1905ddb2345fc3828 (diff)
downloadpylint-062999db0385f9f3f31df47f1ddbf84271ad0ab8.tar.gz
Fix a false positive with dict and not-iterating warnings.
dict accepts iterators, as much as set and list does. This patch fixes this and adds tests for the other callables for which we shouldn't emit.
-rw-r--r--pylint/checkers/python3.py2
-rw-r--r--pylint/test/unittest_checker_python3.py10
2 files changed, 8 insertions, 4 deletions
diff --git a/pylint/checkers/python3.py b/pylint/checkers/python3.py
index 8248e72..e708c4a 100644
--- a/pylint/checkers/python3.py
+++ b/pylint/checkers/python3.py
@@ -50,7 +50,7 @@ def _is_builtin(node):
return getattr(node, 'name', None) in ('__builtin__', 'builtins')
_accepts_iterator = {'iter', 'list', 'tuple', 'sorted', 'set', 'sum', 'any',
- 'all', 'enumerate'}
+ 'all', 'enumerate', 'dict'}
def _in_iterating_context(node):
"""Check if the node is being used as an iterator.
diff --git a/pylint/test/unittest_checker_python3.py b/pylint/test/unittest_checker_python3.py
index e666f75..2407fc5 100644
--- a/pylint/test/unittest_checker_python3.py
+++ b/pylint/test/unittest_checker_python3.py
@@ -117,8 +117,8 @@ class Python3CheckerTest(testutils.CheckerTestCase):
with self.assertAddsMessages(message):
self.checker.visit_callfunc(node)
- def as_argument_to_list_constructor_test(self, fxn):
- module = test_utils.build_module("x = list({}())".format(fxn))
+ def as_argument_to_callable_constructor_test(self, fxn, callable_fn):
+ module = test_utils.build_module("x = {}({}())".format(callable_fn, fxn))
with self.assertNoMessages():
self.walk(module)
@@ -147,10 +147,14 @@ class Python3CheckerTest(testutils.CheckerTestCase):
self.as_iterable_in_listcomp_test(fxn)
self.as_used_in_variant_in_genexp_test(fxn)
self.as_used_in_variant_in_listcomp_test(fxn)
- self.as_argument_to_list_constructor_test(fxn)
self.as_argument_to_random_fxn_test(fxn)
self.as_argument_to_str_join_test(fxn)
+ for func in ('iter', 'list', 'tuple', 'sorted',
+ 'set', 'sum', 'any', 'all',
+ 'enumerate', 'dict'):
+ self.as_argument_to_callable_constructor_test(fxn, func)
+
@python2_only
def test_map_in_iterating_context(self):
self.iterating_context_tests('map')