[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gnulib-tool.py: Fix pylint 'attribute-defined-outside-init' warnings
From: |
Bruno Haible |
Subject: |
Re: gnulib-tool.py: Fix pylint 'attribute-defined-outside-init' warnings. |
Date: |
Wed, 17 Apr 2024 20:02:33 +0200 |
Hi Collin,
> $ pylint *.py | grep W0201
> GLError.py:119:12: W0201: Attribute 'message' defined outside __init__
> (attribute-defined-outside-init)
This warning is bogus. In a dynamic language like Python, it is
perfectly fine to have a property used only by one method. Only if
it is used by more than one method, would I find it suitable to
declare/initialize it in the constructor.
Your patch is not good, because it increases the code that is
necessary to read, in order to understand the property: before,
it was one method, now it would be the class.
Maybe you can silence the warning by prepending a '_' to the
property name? That would be acceptable.
> GLImport.py:1043:8: W0201: Attribute 'assistant' defined outside __init__
> (attribute-defined-outside-init)
Similarly. In the current state, this property could be turned into a
local variable. If you need this attribute in other methods (see the
other thread), please find a good place to initialize it. But the
proposed patch here is not good, as it initializes the same property
twice, and who knows if both initializations are really equivalent?
> GLModuleSystem.py:916:8: W0201: Attribute 'modules' defined outside __init__
> (attribute-defined-outside-init)
This part is good; applied.
> GLError seems like it was never completed, since we have the error
> messages repeated under "if __name__ == '__main__':".
I understand the reasoning to have library exception handling in a
different place than program exception handling. But if you can
reasonably improve this part, I'd like to see it.
> We already unnecessarily create a
> GLFileSystem that we don't need to [2] [3]. :)
You're welcome to remove the unneeded property.
Bruno
- gnulib-tool.py: Fix pylint 'attribute-defined-outside-init' warnings., Collin Funk, 2024/04/17
- Re: gnulib-tool.py: Fix pylint 'attribute-defined-outside-init' warnings.,
Bruno Haible <=
- Re: gnulib-tool.py: Fix pylint 'attribute-defined-outside-init' warnings., Collin Funk, 2024/04/17
- Re: gnulib-tool.py: Fix pylint 'attribute-defined-outside-init' warnings., Bruno Haible, 2024/04/17
- Re: gnulib-tool.py: Fix pylint 'attribute-defined-outside-init' warnings., Collin Funk, 2024/04/17
- Re: gnulib-tool.py: Fix pylint 'attribute-defined-outside-init' warnings., Bruno Haible, 2024/04/18
- Re: gnulib-tool.py: Fix pylint 'attribute-defined-outside-init' warnings., Collin Funk, 2024/04/18
- Re: gnulib-tool.py: Fix pylint 'attribute-defined-outside-init' warnings., Bruno Haible, 2024/04/19