467,888 Members | 1,411 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,888 developers. It's quick & easy.

pylint: What's wrong with the builtin map()

#!/usr/bin/python
"""test pydev_0.9.3/../pylint"""
__revision__ = "test_mod 0.1 by TV 06/10/22"

lst = ['aaa', ' bbb', '\tccc\n']
lst = map(lambda x: x.strip(), lst)

result = """
No config file found, using default configuration
************* Module test_mod
W: 6: Used builtin function 'map'
E: 6: Using variable 'x' before assigment
....
"""
Oct 22 '06 #1
  • viewed: 10589
Share:
5 Replies
Tuomas wrote:
#!/usr/bin/python
"""test pydev_0.9.3/../pylint"""
__revision__ = "test_mod 0.1 by TV 06/10/22"

lst = ['aaa', ' bbb', '\tccc\n']
lst = map(lambda x: x.strip(), lst)

result = """
No config file found, using default configuration
************* Module test_mod
W: 6: Used builtin function 'map'
E: 6: Using variable 'x' before assigment
Some people think that all occurences of map() must be replaced
by list comprehensions. The designer of pylint seems to be
one of those.

Georg
Oct 22 '06 #2
Tuomas wrote:
lst = map(lambda x: x.strip(), lst)
list comprehensions are more efficient than map/lambda combinations;
the above is better written as:

lst = [x.strip() for x in lst]

in general, map() works best when the callable is an existing function
(especially if it's a built-in). not sure if pylist is smart enough to
tell the difference, though.

</F>

Oct 22 '06 #3
Georg Brandl wrote:
Some people think that all occurences of map() must be replaced
by list comprehensions. The designer of pylint seems to be
one of those.
So it seems, but why? Formally spoken we ase "using variable 'x' before
assigment" in the comprehension too.

#!/usr/bin/python
"""test pydev_0.9.3/../pylint"""
__revision__ = "test_mod 0.2 by TV 06/10/22"

lst = ['aaa', ' bbb', '\tccc\n']
# lst = (lambda x: x.strip(), lst) # revision 0.1
lst = [x.strip() for x in lst]

result = """revision 0.1:
No config file found, using default configuration
************* Module test_mod
W: 6: Used builtin function 'map'
E: 6: Using variable 'x' before assigment
....

revision 0.2:
....
Your code has been rated at 10.00/10 (previous run: -10.00/10)
"""
Oct 22 '06 #4
Tuomas wrote:
Georg Brandl wrote:
>Some people think that all occurences of map() must be replaced
by list comprehensions. The designer of pylint seems to be
one of those.

So it seems, but why?
See Fredrik's post. There's no error in the expression with map(),
it's just less effective than a LC, but only if used with a
lambda.
Formally spoken we ase "using variable 'x' before
assigment" in the comprehension too.
That's another issue. I'd suggest a bug in pylint. (You probably
have a variable called "x" later in the file.

My version of pylint (0.12.1) doesn't show this "error".

Georg
Oct 22 '06 #5
Tuomas wrote:
#!/usr/bin/python
"""test pydev_0.9.3/../pylint"""
__revision__ = "test_mod 0.1 by TV 06/10/22"

lst = ['aaa', ' bbb', '\tccc\n']
lst = map(lambda x: x.strip(), lst)

result = """
No config file found, using default configuration
************* Module test_mod
W: 6: Used builtin function 'map'
E: 6: Using variable 'x' before assigment
...
"""
In addition to what the others said, note that pylint is entirely configurable.
If you don't want to be bothered with warnings about map() which you are going
to ignore, a simple modification to the pylint configuration file will prevent
it from doing that check.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Oct 22 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

226 posts views Thread by Stephen C. Waterbury | last post: by
4 posts views Thread by Michael Yanowitz | last post: by
7 posts views Thread by montyphyton | last post: by
2 posts views Thread by lgfang | last post: by
2 posts views Thread by Mick Charles Beaver | last post: by
2 posts views Thread by dmitrey | last post: by
1 post views Thread by Stefan Rank | last post: by
32 posts views Thread by Stephen Horne | last post: by
2 posts views Thread by GHUM | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.