I mentioned a change involving moving an attribute definition to its
proper place in __init__ here:
https://lists.gnu.org/archive/html/bug-gnulib/2024-04/msg00270.html
But I noticed that pylint will warn about these [1]. So it seems
easier to fix them all at once instead of in the middle of other
changes.
$ pylint *.py | grep W0201
GLError.py:119:12: W0201: Attribute 'message' defined outside __init__
(attribute-defined-outside-init)
GLImport.py:1043:8: W0201: Attribute 'assistant' defined outside __init__
(attribute-defined-outside-init)
GLModuleSystem.py:916:8: W0201: Attribute 'modules' defined outside __init__
(attribute-defined-outside-init)
GLError seems like it was never completed, since we have the error
messages repeated under "if __name__ == '__main__':". But it seems
__repr__ expects 'messages' to be initialized to None. So we can just
do that now in __init__.
GLImport defines 'assistant' in GLImport.execute(). I plan to remove
that definition and just mutate an instance attribute. Before that
change, it is harmless to initialize it to a GLFileAssistant in
__init__ so lets do that. We already unnecessarily create a
GLFileSystem that we don't need to [2] [3]. :)
The GLModuleSystem.transitive_closure() function defines a 'modules'
attribute that is never used. We can just remove it.
[1]
https://pylint.readthedocs.io/en/latest/user_guide/messages/warning/attribute-defined-outside-init.html
[2]
https://git.savannah.gnu.org/cgit/gnulib.git/tree/pygnulib/GLImport.py?id=64a7072ee8636c53bc2000505668bd0e33bb427e#n305
[3]
https://git.savannah.gnu.org/cgit/gnulib.git/tree/pygnulib/GLImport.py?id=64a7072ee8636c53bc2000505668bd0e33bb427e#n1134
Collin
From 583b0470f53a3ed707c3a809ac209747780fa490 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Tue, 16 Apr 2024 20:21:04 -0700
Subject: [PATCH] gnulib-tool.py: Fix pylint 'attribute-defined-outside-init'
warnings.
* pygnulib/GLError.py (GLError.__init__): Define the 'messages'
attribute to None.
* pygnulib/GLImport.py (GLImport.__init__): Define the 'assistant'
attribute to a GLFileAssistant object.
* pygnulib/GLModuleSystem.py (GLModuleTable.transitive_closure): Don't
define a 'modules' attribute since it is never used.
---
ChangeLog | 10 ++++++++++
pygnulib/GLError.py | 1 +
pygnulib/GLImport.py | 1 +
pygnulib/GLModuleSystem.py | 1 -
4 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index ffe35d5d1d..863a750109 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-04-16 Collin Funk <collin.fu...@gmail.com>
+
+ gnulib-tool.py: Fix pylint 'attribute-defined-outside-init' warnings.
+ * pygnulib/GLError.py (GLError.__init__): Define the 'messages'
+ attribute to None.
+ * pygnulib/GLImport.py (GLImport.__init__): Define the 'assistant'
+ attribute to a GLFileAssistant object.
+ * pygnulib/GLModuleSystem.py (GLModuleTable.transitive_closure): Don't
+ define a 'modules' attribute since it is never used.
+
2024-04-16 Sam James <s...@gentoo.org>
wchar: Fix serial number.
diff --git a/pygnulib/GLError.py b/pygnulib/GLError.py
index a990c382b1..fd7cb96975 100644
--- a/pygnulib/GLError.py
+++ b/pygnulib/GLError.py
@@ -68,6 +68,7 @@ def __init__(self, errno: int, errinfo: str | float | None = None) -> None:
self.errno = errno
self.errinfo = errinfo
self.args = (self.errno, self.errinfo)
+ self.message = None
def __repr__(self) -> str:
errno = self.errno
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index c6a4693c90..a68399f561 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -304,6 +304,7 @@ def __init__(self, config: GLConfig, mode: int) -> None:
self.emitter = GLEmiter(self.config)
self.filesystem = GLFileSystem(self.config)
self.modulesystem = GLModuleSystem(self.config)
+ self.assistant = GLFileAssistant(self.config)
self.moduletable = GLModuleTable(self.config,
self.config.checkInclTestCategory(TESTS['all-tests']),
self.config.checkInclTestCategory(TESTS['all-tests']))
diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py
index 6aed38b9eb..40ac591dc4 100644
--- a/pygnulib/GLModuleSystem.py
+++ b/pygnulib/GLModuleSystem.py
@@ -913,7 +913,6 @@ def transitive_closure(self, modules: list[GLModule]) -> list[GLModule]:
inmodules = sorted(set(inmodules))
inc_all_tests = self.inc_all_indirect_tests
modules = sorted(set(outmodules))
- self.modules = modules
return modules
def transitive_closure_separately(self, basemodules: list[GLModule],
--
2.44.0