473,415 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,415 software developers and data experts.

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
5 11115
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

226
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python 2.3.2 (#1, Oct 20 2003, 01:04:35) on linux2 Type...
4
by: Michael Yanowitz | last post by:
Hello: I ran the new pylint and my code and I had a few questions on why those are warnings or what I can do to fix them: 1) W: 0: Too many lines in module (1587) Why is 1587 considered too...
7
by: montyphyton | last post by:
Some recent posts about Python programming style got me thinking. Since we have the PEP 8 which gives some guidelines about the style to be used, do we have any program that can check for...
2
by: lgfang | last post by:
Hi, I think this is a bug of pylint.el. But I failed finding a way to submit the bug neither in its official site nor in google. So I post it here wishing it may be useful for some buddies. ...
2
by: Mick Charles Beaver | last post by:
Hello, I've been looking into using PyLint on some of my programs, just as a best practices kind of thing. Here's a snippet:...
2
by: dmitrey | last post by:
Hi all, I have Eric 4.1.1, pylint and Eric pylint plugin installed, but I cannot find how to use pylint from Eric IDE GUI. Does anyone know? Thank you in advance, D.
1
by: Stefan Rank | last post by:
on 31.07.2008 11:29 Diez B. Roggisch said the following: <snip> <snip> Three installations of pylint 0.14.0 that I have access to from here: pylint.bat 0.14.0, astng 0.17.2, common 0.27.0...
32
by: Stephen Horne | last post by:
I've been using Visual C++ 2003 for some time, and recently started working on making my code compile in GCC and MinGW. I hit on lots of unexpected problems which boil down to the same template...
2
by: GHUM | last post by:
Hello, I am pylinting some software of mine. Now pylint throws messages, and I know of pylint --help-msg to get some more text. What is missing out are explanation, WHY some things are bad,...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.