From 60cf5da7155a4b4eb255704e76124981928a300a Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Mon, 8 Apr 2024 03:41:53 -0700 Subject: [PATCH 7/7] gnulib-tool.py: Use a defaultdict to simplify code. * pygnulib/GLModuleSystem.py (GLModuleTable.__init__): Use a defaultdict so the initial value for a key is handled for us. (GLModuleTable.addConditional): Remove the initial value case. --- ChangeLog | 7 +++++++ pygnulib/GLModuleSystem.py | 8 +++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index db7b7ca3ec..e4b70568ab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2024-04-08 Collin Funk + + gnulib-tool.py: Use a defaultdict to simplify code. + * pygnulib/GLModuleSystem.py (GLModuleTable.__init__): Use a defaultdict + so the initial value for a key is handled for us. + (GLModuleTable.addConditional): Remove the initial value case. + 2024-04-08 Collin Funk gnulib-tool.py: Use a set instead of list for avoided module checks. diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py index 60e9846a66..a190b053ab 100644 --- a/pygnulib/GLModuleSystem.py +++ b/pygnulib/GLModuleSystem.py @@ -24,6 +24,7 @@ import sys import codecs import hashlib import subprocess as sp +from collections import defaultdict from . import constants from .GLError import GLError from .GLConfig import GLConfig @@ -732,7 +733,7 @@ class GLModuleTable: returns the condition when B should be enabled as a dependency of A, once the m4 code for A has been executed. ''' - self.dependers = dict() # Dependencies + self.dependers = defaultdict(list) # Dependencies self.conditionals = dict() # Conditional modules self.unconditionals = dict() # Unconditional modules self.base_modules = [] # Base modules @@ -789,10 +790,7 @@ class GLModuleTable: % type(condition).__name__) if not str(module) in self.unconditionals: # No unconditional dependency to the given module is known at this point. - if str(module) not in self.dependers: - self.dependers[str(module)] = [] - if str(parent) not in self.dependers[str(module)]: - self.dependers[str(module)].append(str(parent)) + self.dependers[str(module)].append(str(parent)) key = '%s---%s' % (str(parent), str(module)) self.conditionals[key] = condition -- 2.44.0