bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] gnulib-tool.py: Follow gnulib-tool changes, part 33.


From: Collin Funk
Subject: Re: [PATCH] gnulib-tool.py: Follow gnulib-tool changes, part 33.
Date: Thu, 29 Feb 2024 03:50:01 -0800
User-agent: Mozilla Thunderbird

Hi Bruno,

On 2/29/24 2:48 AM, Bruno Haible wrote:
> One question: Why this change?
> 
> -        tests_modules = sorted(set(tests_modules))
> +        tests_modules = sorted(list(set(tests_modules)))
> 
> IMO, it is redundant, because sorted() of a set returns a list anyway.

Ah, I had a feeling that it was redundant after sending the email.
Thanks for confirming it for me. For some reason I was thinking that
sorted() would return the same type it was given.

Was gnulib-tool.py originally written in Python 2? I don't feel like I
don't see 'type(var) == list' anymore (in the very little Python code
I read). Usually I feel like you would check if something is iterable
like so [1] [2]:

     #!/usr/bin/env python3

     import collections.abc


     def is_iterable(var):
         return isinstance(var, collections.abc.Iterable)


     print(f'1. List:   {is_iterable(list())}')
     print(f'2. Set:    {is_iterable(set())}')
     print(f'3. String: {is_iterable(str())}')
     print(f'4. Dict:   {is_iterable(dict())}')
     print(f'5. Int:    {is_iterable(int())}')
     print(f'6. Float:  {is_iterable(float())}')

     $ ./example.py 
     1. List:   True
     2. Set:    True
     3. String: True
     4. Dict:   True
     5. Int:    False
     6. Float:  False

Python has added a lot of interesting type hinting stuff over the past
few years [3]. Reading the union types was a bit confusing at first
since I didn't know they were added [4]. But I feel like I remember
linters using them pretty well. Of course it is still Python though so
no one is stopping you from going against the hints. :)

[1] https://docs.python.org/3/library/functions.html#isinstance
[2] https://docs.python.org/3/library/collections.abc.html
[3] https://peps.python.org/pep-0484/
[4] https://peps.python.org/pep-0604/

Collin



reply via email to

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