Hi Bruno,
I was having a look at GLModuleSystem.py and noticed some duplicate
checks that an key is valid. Patch 0003 addresses that.
Patch 0004 adds a missing None return type hint to
GLModuleTable.getCondition(). This is used to indicate that the module
is not a conditional dependency. I missed this in the type hint patch.
This was also one of the functions you mentioned here:
https://lists.gnu.org/archive/html/bug-gnulib/2024-03/msg00360.html
> * In GLModuleSystem.py lines 784, 821:
> A condition can be a string or True. But
> str | bool
> makes it look like False was also a valid value. Is possible to
> write
> str | True
> in some way?
The correct way to do this is Literal[True] after the import:
from typing import Literal
but I wasn't sure if it was compatible with Python 3.7. I ended up
trying it and it is compatible with Python 3.7. The documentation says
Python 3.8 which I've confirmed with my installation [1].
Here is the thread we chose Python 3.7:
https://lists.gnu.org/archive/html/bug-gnulib/2024-03/msg00004.html
It appears it is EOL but I'm not sure how RHEL / CentOS versions and
packages work [2]. Does the next version default to 3.7? It looks like
they ship a few and allow you to use 'alternatives --set', but I am
unsure which is default.
[1] https://docs.python.org/3/library/typing.html#typing.Literal
[2] https://devguide.python.org/versions
Collin
From 415efd4e122ec5377d890f3e44a992eb7b06986d Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Sun, 7 Apr 2024 22:00:48 -0700
Subject: [PATCH 3/4] gnulib-tool.py: Remove unnecessary conditional.
* pygnulib/GLModuleSystem.py (GLModuleTable.__getitem__): Don't check if
the key is valid twice.
---
ChangeLog | 6 ++++++
pygnulib/GLModuleSystem.py | 21 ++++++++++-----------
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index cb563b3830..2bae9994dd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-04-07 Collin Funk <collin.fu...@gmail.com>
+
+ gnulib-tool.py: Remove unnecessary conditional.
+ * pygnulib/GLModuleSystem.py (GLModuleTable.__getitem__): Don't check if
+ the key is valid twice.
+
2024-04-07 Collin Funk <collin.fu...@gmail.com>
gnulib-tool.py: Remove a unused and incorrect function.
diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py
index 3997668538..d3f38c2b66 100644
--- a/pygnulib/GLModuleSystem.py
+++ b/pygnulib/GLModuleSystem.py
@@ -763,17 +763,16 @@ class GLModuleTable:
def __getitem__(self, y: str) -> list[GLModule]:
'''x.__getitem__(y) <==> x[y]'''
- if y in ['base', 'final', 'main', 'tests', 'avoids']:
- if y == 'base':
- return self.getBaseModules()
- elif y == 'final':
- return self.getFinalModules()
- elif y == 'main':
- return self.getMainModules()
- elif y == 'tests':
- return self.getTestsModules()
- else: # if y == 'avoids'
- return self.getAvoids()
+ if y == 'base':
+ return self.getBaseModules()
+ elif y == 'final':
+ return self.getFinalModules()
+ elif y == 'main':
+ return self.getMainModules()
+ elif y == 'tests':
+ return self.getTestsModules()
+ elif y == 'avoids':
+ return self.getAvoids()
else: # if y is not in list
raise KeyError('GLModuleTable does not contain key: %s' % repr(y))
--
2.44.0
From 61f1bf56f271581555e60aa3d20edbc448565eb9 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Sun, 7 Apr 2024 22:22:49 -0700
Subject: [PATCH 4/4] gnulib-tool.py: Fix incomplete type hint.
* pygnulib/GLModuleSystem.py (GLModuleTable.getCondition): Add None to
the return type hint. This is the return value when the module is not a
conditional dependency.
---
ChangeLog | 7 +++++++
pygnulib/GLModuleSystem.py | 2 +-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 2bae9994dd..0f0aedd2d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-04-07 Collin Funk <collin.fu...@gmail.com>
+
+ gnulib-tool.py: Fix incomplete type hint.
+ * pygnulib/GLModuleSystem.py (GLModuleTable.getCondition): Add None to
+ the return type hint. This is the return value when the module is not a
+ conditional dependency.
+
2024-04-07 Collin Funk <collin.fu...@gmail.com>
gnulib-tool.py: Remove unnecessary conditional.
diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py
index d3f38c2b66..761c43c2e0 100644
--- a/pygnulib/GLModuleSystem.py
+++ b/pygnulib/GLModuleSystem.py
@@ -813,7 +813,7 @@ class GLModuleTable:
result = str(module) in self.dependers
return result
- def getCondition(self, parent: GLModule, module: GLModule) -> str | bool:
+ def getCondition(self, parent: GLModule, module: GLModule) -> str | bool | None:
'''Return condition from parent to module. Condition can be string or True.
If module is not in the list of conddeps, method returns None.'''
if type(parent) is not GLModule:
--
2.44.0