Skip to content

Commit

Permalink
Fix false positive when map() receives iterable
Browse files Browse the repository at this point in the history
Since map() supports iterables, it should not issue
builtin-not-iterating for iterable arguments.

Signed-off-by: Tiago Honorato <tiagohonorato1@gmail.com>
  • Loading branch information
tiagohonorato authored and Pierre-Sassoulas committed Feb 20, 2021
1 parent ba6a403 commit 419d23f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,5 @@ contributors:
* Marc Mueller (cdce8p): contributor

* David Gilman: contributor

* Tiago Honorato: contributor
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion doc/whatsnew/2.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions pylint/checkers/python3.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def _is_builtin(node):
"frozenset",
"OrderedDict",
"zip",
"map",
}
ATTRIBUTES_ACCEPTS_ITERATOR = {"join", "from_iterable"}
_BUILTIN_METHOD_ACCEPTS_ITERATOR = {
Expand Down
7 changes: 6 additions & 1 deletion tests/checkers/unittest_python3.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ def as_argument_to_zip_test(self, fxn):
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"""
Expand Down Expand Up @@ -224,7 +229,7 @@ def iterating_context_tests(self, fxn):
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",
Expand Down

0 comments on commit 419d23f

Please sign in to comment.