There are a few cases of statements like this:
var = None
try:
# do something
var = True
except:
var = False
or:
var = None
if other_condition:
var = True
else:
var = False
Since the 'var' will be set to a bool unconditionally, the None is
never used.
Collin
From 1d7f51cf310ac6ffbf531a85ddeda124f075630b Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Sun, 14 Apr 2024 09:37:17 -0700
Subject: [PATCH] gnulib-tool.py: Remove some unused variables.
* pygnulib/GLEmiter.py (GLEmiter.autoconfSnippets): Remove unused
variable.
* pygnulib/GLInfo.py (GLInfo.date, GLInfo.version): Remove variables
unconditionally set in try, except blocks.
* pygnulib/GLModuleSystem.py (GLModule.getConditionalName)
(GLModule.getShellFunc, GLModule.getShellVar): Remove variables
unconditionally set in if, else blocks.
---
ChangeLog | 11 +++++++++++
pygnulib/GLEmiter.py | 1 -
pygnulib/GLInfo.py | 3 ---
pygnulib/GLModuleSystem.py | 3 ---
4 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4333a003a5..9b40f3d9d8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2024-04-14 Collin Funk <collin.fu...@gmail.com>
+
+ gnulib-tool.py: Remove some unused variables.
+ * pygnulib/GLEmiter.py (GLEmiter.autoconfSnippets): Remove unused
+ variable.
+ * pygnulib/GLInfo.py (GLInfo.date, GLInfo.version): Remove variables
+ unconditionally set in try, except blocks.
+ * pygnulib/GLModuleSystem.py (GLModule.getConditionalName)
+ (GLModule.getShellFunc, GLModule.getShellVar): Remove variables
+ unconditionally set in if, else blocks.
+
2024-04-14 Collin Funk <collin.fu...@gmail.com>
gnulib-tool.py: Don't use mutable default arguments.
diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py
index 6edad6619e..558f130bbb 100644
--- a/pygnulib/GLEmiter.py
+++ b/pygnulib/GLEmiter.py
@@ -324,7 +324,6 @@ def autoconfSnippets(self, modules: list[GLModule], referenceable_modules: list[
for module in modules:
if module_filter(module):
if moduletable.isConditional(module):
- shellvar = module.getShellVar()
emit += ' %s=false\n' % module.getShellVar()
# Emit the autoconf code for the conditional modules, each in a separate
# function. This makes it possible to support cycles among conditional
diff --git a/pygnulib/GLInfo.py b/pygnulib/GLInfo.py
index 716d1ddf0d..c7de90376a 100644
--- a/pygnulib/GLInfo.py
+++ b/pygnulib/GLInfo.py
@@ -89,14 +89,12 @@ def copyright(self) -> str:
def date(self) -> str:
'''Return formatted string which contains date and time in GMT format.'''
if isdir(DIRS['git']):
- have_git = None
try:
sp.check_call(['git', '--version'], stdout=sp.DEVNULL)
have_git = True
except:
have_git = False
if have_git:
- have_GNU_date = None
try:
sp.check_call(['date', '--version'], stdout=sp.DEVNULL)
have_GNU_date = True
@@ -332,7 +330,6 @@ def usage(self) -> str:
def version(self) -> str:
'''Return formatted string which contains git version.'''
if isdir(DIRS['git']):
- have_git = None
try:
sp.check_call(['git', '--version'], stdout=sp.DEVNULL)
have_git = True
diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py
index 6639c9a6e8..2551e316e1 100644
--- a/pygnulib/GLModuleSystem.py
+++ b/pygnulib/GLModuleSystem.py
@@ -396,7 +396,6 @@ def getShellFunc(self) -> str:
if char not in GLModule.shell_id_chars:
valid_shell_id = False
break
- identifier = None
if valid_shell_id:
identifier = self.getName()
else:
@@ -414,7 +413,6 @@ def getShellVar(self) -> str:
if char not in GLModule.shell_id_chars:
valid_shell_id = False
break
- identifier = None
if valid_shell_id:
identifier = self.getName()
else:
@@ -432,7 +430,6 @@ def getConditionalName(self) -> str:
if char not in GLModule.shell_id_chars:
valid_shell_id = False
break
- identifier = None
if valid_shell_id:
identifier = self.getName()
else:
--
2.44.0