bug-gnulib
[Top][All Lists]
Advanced

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

Opinions on two pylint warnings?


From: Collin Funk
Subject: Opinions on two pylint warnings?
Date: Thu, 4 Apr 2024 04:07:35 -0700
User-agent: Mozilla Thunderbird

Right now I am seeing two warnings from pylint that I would like to
silence:

The first is W0707 [1]. It recommends chaining exceptions. So this:

    try:  # Try to apply patch
        sp.check_call(command, shell=True)
    except sp.CalledProcessError:
        raise GLError(2, name)

becomes:

    try:  # Try to apply patch
        sp.check_call(command, shell=True)
    except sp.CalledProcessError as exc:
        raise GLError(2, name) from exc

This is used for the exception backtrace messages. Most of the
exceptions that we catch are used to throw GLError exceptions to print
similar warnings to gnulib-tool.sh. Because of that, I am fine with
disabling this warning unless anyone disagrees.

The second warning is R1735 [1]. It suggests changing 'dict()' to
'{}'. I am fine with making that change or silencing the warning.

I prefer the appearance of '{}', but can understand why some might
dislike it:

   Dictionary:
       var = {} # Empty dictionary.
       # {0: 'a', 1: 'b', 2: 'c'}
       var = {i : chr(ord('a') + i) for i in range(3)} 

   Set:
       var = set() # We are stuck with this. :(
       # Might be mistaken for a dictionary at a quick glance?
       # {1, 2, 3}
       var = {value for value in [1, 1, 2, 2, 3]}

Any thoughts/preferences? These warnings make it harder to see more
important ones so I would like to fix them.

    $ pylint *.py | grep 'W0707' | wc -l
    15

    $ pylint *.py | grep 'R1735' | wc -l
    19

[1] 
https://pylint.readthedocs.io/en/stable/user_guide/messages/warning/raise-missing-from.html
[2] 
https://pylint.readthedocs.io/en/latest/user_guide/messages/refactor/use-dict-literal.html

Collin



reply via email to

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