Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map-builtin-not-iterating reported with reduce() #3051

Closed
DylanYoung opened this issue Aug 9, 2019 · 9 comments
Closed

map-builtin-not-iterating reported with reduce() #3051

DylanYoung opened this issue Aug 9, 2019 · 9 comments
Labels
Bug 🪲 Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors

Comments

@DylanYoung
Copy link

Steps to reproduce

  1. Create reduce call with a map iterable
  2. Observe pylint complain

Current behavior

  1. W1636(map-builtin-not-iterating) is reported

Expected behavior

  1. No error is reported (reduce is obviously an iterating context)

pylint --version output

pylint 1.9.5,
astroid 1.6.6
Python 2.7.16 (default, Apr 26 2019, 16:26:18)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]

@DylanYoung
Copy link
Author

Note: it looks like a similar bug was fixed here: #2731

But by the looks of it, I suspect it didn't touch either the Py2 case or the six case of using reduce (it explicitly check fro an 'itertools' root), but I could be mistaken.

@PCManticore PCManticore added Bug 🪲 Good first issue Friendly and approachable by new contributors labels Aug 9, 2019
@PCManticore
Copy link
Contributor

Thanks for the report. Yeah, we'll need a separate solution for reduce.

@gyermolenko
Copy link
Contributor

@DylanYoung
Could you please provide an example? I tried this one

print reduce(lambda x, y: x + y, map(str.upper, "abc"))

but didn't get your warning in results

@DylanYoung
Copy link
Author

DylanYoung commented Aug 16, 2019

@gyermolenko Did you do a from six.moves import reduce?

It's possible that it works on Py3 too; I've only tested on Py2.

UPDATE: your example works if you add the import (which is to say, it replicates the bug)

UPDATE AGAIN: the six actually isn't necessary. I'm able to replicate with the code you've provided. Are you sure you have the py3k errors enabled? You can pass the --py3k flag to the CLI or update your config to include these errors.

@DylanYoung
Copy link
Author

DylanYoung commented Aug 16, 2019

@PCManticore Moreover, I am still getting an error withitertools.chain:

from itertools import chain

d1, d2 = {}, {}

chain(d1.items(), d2.items())

@DylanYoung
Copy link
Author

DylanYoung commented Aug 16, 2019

@PCManticore Also, a question, is there a config option to set other iterating contexts? This could be a good temporary work-around and is probably necessary to fully support this type of error code (dependent on the context of user code, which could be a c-extension that pylint knows nothing about). If there isn't, it might be worth thinking about before the EOL of Py2.

@PCManticore
Copy link
Contributor

@DylanYoung Good question, there isn't, but it might be worthwhile to introduce a new option that accepts a list of iterable consuming functions.

@gyermolenko
Copy link
Contributor

To summarize:

Warning in question ((map-builtin-not-iterating))

  • appears only with --py3k option
  • reproducible both for pylint 1.9.5 / python 2.7.16 with python2 example
print reduce(lambda x, y: x + y, map(str.upper, "abc"))

and for pylint 2.3.1 / python 3.7.4 with python3 example

from functools import reduce
print(reduce(lambda x, y: x + y, map(str.upper, "abc")))
  • seems like "(using six or not)" can be removed from the title

====================================================

As for the second issue, with example

from itertools import chain
d1, d2 = {}, {}
chain(d1.items(), d2.items())

warning (dict-items-not-iterating) appears only for python2 and only with --py3k

@PCManticore PCManticore changed the title W1636(map-builtin-not-iterating) Reported in Reduce Call (using six or not) map-builtin-not-iterating reported with reduce() Sep 8, 2019
@Pierre-Sassoulas Pierre-Sassoulas added the Help wanted 🙏 Outside help would be appreciated, good for new contributors label Mar 2, 2021
@Pierre-Sassoulas
Copy link
Member

Won't do, we removed the python3 porting mode in 2.11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors
Projects
None yet
Development

No branches or pull requests

4 participants