diff options
author | Tiago Honorato <tiagohonorato1@gmail.com> | 2021-02-17 22:51:32 -0300 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-02-20 15:26:36 +0100 |
commit | 570e65536147b00ab8a5743e761d7caa326afa21 (patch) | |
tree | 3eedcbdeacf2eabe42c8d0df132025d61a1fb5fa | |
parent | ba6a40363d7273b50078bfb2c18e5d3c41ed73f1 (diff) | |
download | pylint-git-570e65536147b00ab8a5743e761d7caa326afa21.tar.gz |
Fix false positive when map() receives iterable
Since map() supports iterables, it should not issue
builtin-not-iterating for iterable arguments.
Signed-off-by: Tiago Honorato <tiagohonorato1@gmail.com>
-rw-r--r-- | CONTRIBUTORS.txt | 2 | ||||
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | doc/whatsnew/2.7.rst | 2 | ||||
-rw-r--r-- | pylint/checkers/python3.py | 1 | ||||
-rw-r--r-- | tests/checkers/unittest_python3.py | 7 |
5 files changed, 14 insertions, 2 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 037ed3984..8eef266d4 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -445,3 +445,5 @@ contributors: * Marc Mueller (cdce8p): contributor * David Gilman: contributor + +* Tiago Honorato: contributor @@ -5,6 +5,10 @@ Pylint's ChangeLog What's New in Pylint 2.7.0? =========================== +* Fix false positive for ``builtin-not-iterating`` when ``map`` receives iterable + + Closes #4078 + * Python 3.6+ is now required. * Fix false positive for ``builtin-not-iterating`` when ``zip`` receives iterable diff --git a/doc/whatsnew/2.7.rst b/doc/whatsnew/2.7.rst index 154e510a5..7b0fd859f 100644 --- a/doc/whatsnew/2.7.rst +++ b/doc/whatsnew/2.7.rst @@ -29,7 +29,7 @@ New checkers Other Changes ============= -* Fix false positive for ``builtin-not-iterating`` when ``zip`` receives iterable +* Fix false positive for ``builtin-not-iterating`` when ``zip`` or ``map`` receives iterable * Fix linter multiprocessing pool shutdown which triggered warnings when runned in parallels with other pytest plugins. diff --git a/pylint/checkers/python3.py b/pylint/checkers/python3.py index ac2752d27..8d9f7ae98 100644 --- a/pylint/checkers/python3.py +++ b/pylint/checkers/python3.py @@ -97,6 +97,7 @@ _ACCEPTS_ITERATOR = { "frozenset", "OrderedDict", "zip", + "map", } ATTRIBUTES_ACCEPTS_ITERATOR = {"join", "from_iterable"} _BUILTIN_METHOD_ACCEPTS_ITERATOR = { diff --git a/tests/checkers/unittest_python3.py b/tests/checkers/unittest_python3.py index 9c46f4fa8..04ed78a8f 100644 --- a/tests/checkers/unittest_python3.py +++ b/tests/checkers/unittest_python3.py @@ -187,6 +187,11 @@ class TestPython3Checker(testutils.CheckerTestCase): with self.assertNoMessages(): self.walk(module) + def as_argument_to_map_test(self, fxn): + module = astroid.parse(f"list(map(__, {fxn}()))") + with self.assertNoMessages(): + self.walk(module) + def as_iterable_in_unpacking(self, fxn): node = astroid.extract_node( f""" @@ -224,7 +229,7 @@ class TestPython3Checker(testutils.CheckerTestCase): self.as_iterable_in_starred_context(fxn) self.as_argument_to_itertools_functions(fxn) self.as_argument_to_zip_test(fxn) - + self.as_argument_to_map_test(fxn) for func in ( "iter", "list", |