bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gnulib-tool.py: Fix 'consider-using-with' pylint warnings.


From: Bruno Haible
Subject: Re: gnulib-tool.py: Fix 'consider-using-with' pylint warnings.
Date: Fri, 05 Apr 2024 14:58:40 +0200

Hi Collin,

> I've just changed these to 'sp.run()' since that function deals with
> everything for us and is recommended.

Yes, sp.run() and sp.call() are the variants that are most easy to use.

> The second is 'consider-using-set-comprehension'. Instead of calling
> set() on a list comprehension we can just use a set comprehension.
> I've additionally simplified this case:
> 
> -            version = sorted(set([ float(version)
> -                                   for version in versions ]))[-1]
> +            version = max({ float(version)
> +                            for version in versions })
> 
> The previous method is just a less clear way of finding the max:
> 
>     print([1, 2, 3, 4][-1])
>     4

Sure. It was a translation of the shell code:

      autoconf_minversion=`
        for version in $prereqs; do echo $version; done |
        LC_ALL=C sort -nru | sed -e 1q
      `

Finding the maximum of a list directly is O(N). Finding it by sorting
the list is O(N log N). Therefore it is clear which of the two should
be preferred :)

Thanks, applied both patches.

Bruno






reply via email to

[Prev in Thread] Current Thread [Next in Thread]