In GLEmiter.autoconfSnippets I see many warnings that a 'solution'
variable may be unbound when it is used.
if solution: # Solution may be unbound here.
emit += self.autoconfSnippet(module, toplevel,
disable_libtool, disable_gettext,
replace_auxdir, ' ')
It seems that the unbound variable will evaluate to 'False', which
would explain why it still works. Still not good practice. :)
This patch silences the warning by initializing solution to False at
the start of each loop. Easy fix.
Collin
From 742d2367663fb70940d9e7b7ae47d3fed2c83d5e Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Tue, 9 Apr 2024 10:47:23 -0700
Subject: [PATCH] gnulib-tool.py: Fix some unbound variables.
* pygnulib/GLEmiter.py (GLEmiter.autoconfSnippets): Declare the solution
flag and set it to False at the start of each loop.
---
ChangeLog | 6 ++++++
pygnulib/GLEmiter.py | 6 ++++++
2 files changed, 12 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index 033eb5dc92..3086dc7d54 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-04-09 Collin Funk <collin.fu...@gmail.com>
+
+ gnulib-tool.py: Fix some unbound variables.
+ * pygnulib/GLEmiter.py (GLEmiter.autoconfSnippets): Declare the solution
+ flag and set it to False at the start of each loop.
+
2024-04-09 Collin Funk <collin.fu...@gmail.com>
gnulib-tool.py: Change the avoid list to a set for lookups.
diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py
index e6143645be..b7aefa6068 100644
--- a/pygnulib/GLEmiter.py
+++ b/pygnulib/GLEmiter.py
@@ -314,6 +314,7 @@ class GLEmiter:
if not conddeps:
# Ignore the conditions, and enable all modules unconditionally.
for module in modules:
+ solution = False
if verifier == 0:
solution = True
elif verifier == 1:
@@ -326,6 +327,7 @@ class GLEmiter:
else: # if conddeps
# Emit the autoconf code for the unconditional modules.
for module in modules:
+ solution = False
if verifier == 0:
solution = True
elif verifier == 1:
@@ -338,6 +340,7 @@ class GLEmiter:
disable_libtool, disable_gettext, replace_auxdir, ' ')
# Initialize the shell variables indicating that the modules are enabled.
for module in modules:
+ solution = False
if verifier == 0:
solution = True
elif verifier == 1:
@@ -352,6 +355,7 @@ class GLEmiter:
# function. This makes it possible to support cycles among conditional
# modules.
for module in modules:
+ solution = False
if verifier == 0:
solution = True
elif verifier == 1:
@@ -390,6 +394,7 @@ class GLEmiter:
emit += ' }\n'
# Emit the dependencies from the unconditional to the conditional modules.
for module in modules:
+ solution = False
if verifier == 0:
solution = True
elif verifier == 1:
@@ -419,6 +424,7 @@ class GLEmiter:
# Define the Automake conditionals.
emit += ' m4_pattern_allow([^%s_GNULIB_ENABLED_])\n' % macro_prefix
for module in modules:
+ solution = False
if verifier == 0:
solution = True
elif verifier == 1:
--
2.44.0