lint warnings

Discussion in 'Python' started by Andrea Crotti, Feb 14, 2011.

  1. I work on emacs with flymake activated and pylint, pyflakes and pep8 running in background to notify for some style problems.

    Now there are at a couple of pylint warnings which I don't understand
    1. Warning (W, filter_enums): Used builtin function 'map' [2 times]
    what is the problem with using map and other builtin functions?

    2. Warning (W): Relative import 'parameters', should be 'othermodule.parameters'
    if I am in the same directory why should I do a relative import, does it make any difference?

    I think it's more clear/safe to just import the 'parameters', am I wrong?

    Thanks,
    Andrea
     
    Andrea Crotti, Feb 14, 2011
    #1
    1. Advertising

  2. On Tue, 15 Feb 2011 14:10:38 +1100, Ben Finney wrote:

    > Andrea Crotti <> writes:
    >
    >> I work on emacs with flymake activated and pylint, pyflakes and pep8
    >> running in background to notify for some style problems.
    >>
    >> Now there are at a couple of pylint warnings which I don't understand
    >> 1. Warning (W, filter_enums): Used builtin function 'map' [2 times]
    >> what is the problem with using map and other builtin functions?

    >
    > The ‘map’ builtin is deprecated;


    I don't believe it is. Do you have any evidence for this claim?


    > using a list comprehension is neater and more efficient.


    The first is a matter of opinion, the second is demonstrably untrue.


    Testing in Python 3.1, there is no significant difference when the
    function is a pure Python function, although map is slightly faster:


    >>> from timeit import Timer
    >>> t1 = Timer('[f(x) for x in range(1000)]', 'def f(x): return x+1')
    >>> t2 = Timer('list(map(f, range(1000)))', 'def f(x): return x+1')
    >>> t1.timeit(number=100)

    0.09910106658935547
    >>> t2.timeit(number=100)

    0.08968997001647949
    >>> t1.timeit(number=1000)

    0.9915580749511719
    >>> t2.timeit(number=1000)

    0.9404010772705078


    If the function is a built-in written in C, map can be significantly
    faster:

    >>> t1 = Timer('[len(s) for s in "a"*1000]', '')
    >>> t2 = Timer('list(map(len, "a"*1000))', '')
    >>> t1.timeit(number=100)

    0.0598909854888916
    >>> t2.timeit(number=100)

    0.02748703956604004
    >>> t1.timeit(number=10000)

    3.6018471717834473
    >>> t2.timeit(number=10000)

    1.8807408809661865


    The only time list comps are faster is if you have a expression which can
    be executed in-line in the comprehension, but needs to be written as a
    Python function in map. And even then, the difference is just a
    multiplicative constant, not a Big Oh difference.



    --
    Steven
     
    Steven D'Aprano, Feb 15, 2011
    #2
    1. Advertising

  3. Il giorno 15/feb/2011, alle ore 04.10, Ben Finney ha scritto:

    > Andrea Crotti <> writes:
    > The ‘map’ builtin is deprecated; using a list comprehension is neater
    > and more efficient.


    Ok well it depends,
    map(int, biglist)
    is better than:
    [int(x) for x in biglist]
    at least for me.

    Efficiency is probably not a big issue apparently, and it's really not important
    until I see that this is a bottleneck.

    >
    > It makes the code unnecessarily ambiguous; the person reading the code
    > can't tell that it's a relative import.


    Yes but what if I move those two files (parameter and the importing module)
    away, the import will continue to work if it's not relative to the upper directory.
     
    Andrea Crotti, Feb 15, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gerald Britton

    lint warnings

    Gerald Britton, Feb 15, 2011, in forum: Python
    Replies:
    1
    Views:
    228
    Steven D'Aprano
    Feb 15, 2011
  2. Gerald Britton

    lint warnings

    Gerald Britton, Feb 15, 2011, in forum: Python
    Replies:
    0
    Views:
    197
    Gerald Britton
    Feb 15, 2011
  3. Gerald Britton
    Replies:
    1
    Views:
    379
    Steven D'Aprano
    Feb 16, 2011
  4. David Sudolcan
    Replies:
    7
    Views:
    2,087
    Eric Sosman
    Apr 4, 2011
  5. Ted Sung
    Replies:
    1
    Views:
    317
    Sherm Pendley
    Aug 30, 2004
Loading...

Share This Page