[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gnulib-tool.py: Correct type hint and doc string.
From: |
Bruno Haible |
Subject: |
Re: gnulib-tool.py: Correct type hint and doc string. |
Date: |
Sat, 03 Aug 2024 17:08:35 +0200 |
Hi Collin,
> One minor correction I applied. The GLModule.getDependentsRecursively
> function returns 'set[GLModule]' not 'str'.
Thanks.
> The function looks similar to a function I wrote that does this to the
> set before returning:
>
> module_names = sorted([ module.name
> for module in outmodules ])
> return lines_to_multiline(module_names)
>
> So I assume it was just a simple copy past mistake.
It was intentional: I think a function that returns a set[GLModule] is
more reusable than a function that returns a string.
> Now that I think of it I'm not sure why I return a string there. I think
> it is better to return a set and let the caller sort as they wish,
> format for printing, etc.
You're right. Done:
2024-08-03 Bruno Haible <bruno@clisp.org>
gnulib-tool.py: Small refactoring.
Suggested by Collin Funk.
* pygnulib/GLModuleSystem.py (GLModule.getDependenciesRecursively):
Return a set of GLModule.
* pygnulib/main.py (main): Convert the result to a string here.
diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py
index 04bb87a46d..09afcf6883 100644
--- a/pygnulib/GLModuleSystem.py
+++ b/pygnulib/GLModuleSystem.py
@@ -528,9 +528,9 @@ def getDependenciesWithConditions(self) ->
list[tuple[GLModule, str | None]]:
self.cache['dependenciesWithCond'] = result
return self.cache['dependenciesWithCond']
- def getDependenciesRecursively(self) -> str:
- '''Return a list of recursive dependencies of this module separated
- by a newline.'''
+ def getDependenciesRecursively(self) -> set[GLModule]:
+ '''Return a list of recursive dependencies of this module,
+ as a set of GLModule objects.'''
handledmodules = set()
inmodules = set()
outmodules = set()
@@ -551,9 +551,7 @@ def getDependenciesRecursively(self) -> str:
# Remove handledmodules from inmodules.
inmodules = inmodules.difference(handledmodules)
- module_names = sorted([ module.name
- for module in outmodules ])
- return lines_to_multiline(module_names)
+ return outmodules
def getDependents(self) -> list[GLModule]:
'''Return list of dependents (a.k.a. "reverse dependencies"),
diff --git a/pygnulib/main.py b/pygnulib/main.py
index dbff9dc76a..f39a05bfd3 100644
--- a/pygnulib/main.py
+++ b/pygnulib/main.py
@@ -1256,7 +1256,10 @@ def main(temp_directory: str) -> None:
for name in modules:
module = modulesystem.find(name)
if module:
- sys.stdout.write(module.getDependenciesRecursively())
+ dependencies = module.getDependenciesRecursively()
+ dependencies_names = sorted([ m.name
+ for m in dependencies ])
+ sys.stdout.write(lines_to_multiline(dependencies_names))
elif mode == 'extract-dependents':
if avoids: