I'd like to start cleaning up some of the unnecessary list(), tuple(),
dict() calls. This patch just converts:
var = list()
to
var = []
everywhere.
Collin
From 3a3b4f0a21e83ba2d9ea50a1391a4f54a1bdeeaf Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Tue, 2 Apr 2024 11:35:51 -0700
Subject: [PATCH] gnulib-tool.py: Use [] instead of list() to initialize empty
lists.
* pygnulib/*.py: Change occurrences of list() to [].
---
ChangeLog | 5 +++++
pygnulib/GLConfig.py | 22 +++++++++++-----------
pygnulib/GLFileSystem.py | 2 +-
pygnulib/GLImport.py | 24 ++++++++++++------------
pygnulib/GLMakefileTable.py | 2 +-
pygnulib/GLModuleSystem.py | 20 ++++++++++----------
pygnulib/GLTestDir.py | 20 ++++++++++----------
pygnulib/constants.py | 6 +++---
8 files changed, 53 insertions(+), 48 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 6e6ebb6127..d6b9f731bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-04-02 Collin Funk <collin.fu...@gmail.com>
+
+ gnulib-tool.py: Use [] instead of list() to initialize empty lists.
+ * pygnulib/*.py: Change occurrences of list() to [].
+
2024-04-02 Collin Funk <collin.fu...@gmail.com>
gnulib-tool.py: Fix determination whether to add the dummy module.
diff --git a/pygnulib/GLConfig.py b/pygnulib/GLConfig.py
index 716a2cf4d1..10ec5efd37 100644
--- a/pygnulib/GLConfig.py
+++ b/pygnulib/GLConfig.py
@@ -311,7 +311,7 @@ class GLConfig(object):
return 0
elif key in ['localpath', 'modules', 'avoids', 'tests',
'incl_test_categories', 'excl_test_categories']:
- return list()
+ return []
elif key in ['libtool', 'gnu_make', 'automake_subdir',
'automake_subdir_tests', 'conddeps',
'libtests', 'dryrun']:
@@ -535,7 +535,7 @@ class GLConfig(object):
'''Set the modules list.'''
if type(modules) is list or type(modules) is tuple:
old_modules = self.table['modules']
- self.table['modules'] = list()
+ self.table['modules'] = []
for module in modules:
try: # Try to add each module
self.addModule(module)
@@ -551,7 +551,7 @@ class GLConfig(object):
def resetModules(self) -> None:
'''Reset the list of the modules.'''
- self.table['modules'] = list()
+ self.table['modules'] = []
# Define avoids methods.
def addAvoid(self, module: str) -> None:
@@ -581,7 +581,7 @@ class GLConfig(object):
'''Specify the modules which will be avoided.'''
if type(modules) is list or type(modules) is tuple:
old_avoids = self.table['avoids']
- self.table['avoids'] = list()
+ self.table['avoids'] = []
for module in modules:
try: # Try to add each module
self.addAvoid(module)
@@ -597,7 +597,7 @@ class GLConfig(object):
def resetAvoids(self) -> None:
'''Reset the list of the avoided modules.'''
- self.table['avoids'] = list()
+ self.table['avoids'] = []
# Define files methods.
def addFile(self, file: str) -> None:
@@ -626,7 +626,7 @@ class GLConfig(object):
'''Specify the list of files.'''
if type(files) is list or type(files) is tuple:
old_files = self.table['files']
- self.table['files'] = list()
+ self.table['files'] = []
for file in files:
try: # Try to add each file
self.addFile(file)
@@ -642,7 +642,7 @@ class GLConfig(object):
def resetFiles(self) -> None:
'''Reset the list of files.'''
- self.table['files'] = list()
+ self.table['files'] = []
# Define incl_test_categories methods
def checkInclTestCategory(self, category: int) -> bool:
@@ -684,7 +684,7 @@ class GLConfig(object):
'''Specify the test categories that should be included.'''
if type(categories) is list or type(categories) is tuple:
old_categories = self.table['incl_test_categories']
- self.table['incl_test_categories'] = list()
+ self.table['incl_test_categories'] = []
for category in categories:
try: # Try to enable each category
self.enableInclTestCategory(category)
@@ -697,7 +697,7 @@ class GLConfig(object):
def resetInclTestCategories(self) -> None:
'''Reset test categories.'''
- self.table['incl_test_categories'] = list()
+ self.table['incl_test_categories'] = []
# Define excl_test_categories methods
def checkExclTestCategory(self, category: int) -> bool:
@@ -732,7 +732,7 @@ class GLConfig(object):
'''Specify the test categories that should be excluded.'''
if type(categories) is list or type(categories) is tuple:
old_categories = self.table['excl_test_categories']
- self.table['excl_test_categories'] = list()
+ self.table['excl_test_categories'] = []
for category in categories:
try: # Try to enable each category
self.enableExclTestCategory(category)
@@ -745,7 +745,7 @@ class GLConfig(object):
def resetExclTestCategories(self) -> None:
'''Reset test categories.'''
- self.table['excl_test_categories'] = list()
+ self.table['excl_test_categories'] = []
# Define libname methods.
def getLibName(self) -> str:
diff --git a/pygnulib/GLFileSystem.py b/pygnulib/GLFileSystem.py
index 40e7c7615d..cb485cf2e8 100644
--- a/pygnulib/GLFileSystem.py
+++ b/pygnulib/GLFileSystem.py
@@ -177,7 +177,7 @@ class GLFileAssistant(object):
% (key, type(value).__name__))
self.original = None
self.rewritten = None
- self.added = list()
+ self.added = []
self.config = config
self.transformers = transformers
self.filesystem = GLFileSystem(self.config)
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index ab740b05ca..f87ba65109 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -318,7 +318,7 @@ class GLImport(object):
sourcebase = self.cache['sourcebase']
m4base = self.cache['m4base']
testsbase = self.cache['testsbase']
- result = list()
+ result = []
for file in files:
if file.startswith('build-aux/'):
path = constants.substart('build-aux/', '%s/' % auxdir, file)
@@ -355,7 +355,7 @@ class GLImport(object):
sourcebase = self.config['sourcebase']
m4base = self.config['m4base']
testsbase = self.config['testsbase']
- result = list()
+ result = []
for file in files:
if file.startswith('build-aux/'):
path = constants.substart('build-aux/', '%s/' % auxdir, file)
@@ -864,7 +864,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
self.moduletable.setTestsModules(tests_modules)
# Check license incompatibilities.
- listing = list()
+ listing = []
compatibilities = dict()
compatibilities['all'] = ['GPLv2+ build tool', 'GPLed build tool',
'public domain', 'unlimited',
@@ -940,8 +940,8 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
transformers['aux'] = sed_transform_build_aux_file
transformers['main'] = sed_transform_main_lib_file
transformers['tests'] = sed_transform_testsrelated_lib_file
- old_table = list()
- new_table = list()
+ old_table = []
+ new_table = []
for src in old_files:
dest = self.rewrite_old_files([src])[-1]
old_table += [tuple([dest, src])]
@@ -958,8 +958,8 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
sorted(set(old_table), key=lambda t: tuple(t[0].lower()))
filetable['new'] = \
sorted(set(new_table), key=lambda t: tuple(t[0].lower()))
- filetable['added'] = list()
- filetable['removed'] = list()
+ filetable['added'] = []
+ filetable['removed'] = []
# Return the result.
result = tuple([filetable, transformers])
@@ -1324,7 +1324,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
if vc_files != False:
# Update the .cvsignore and .gitignore files.
- ignorelist = list()
+ ignorelist = []
# Treat gnulib-comp.m4 like an added file, even if it already existed.
filetable['added'] += [joinpath(m4base, 'gnulib-comp.m4')]
filetable['added'] = sorted(set(filetable['added']))
@@ -1338,8 +1338,8 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
# Sort ignorelist by directory.
ignorelist = sorted(ignorelist, key=lambda row: row[0])
last_dir = ''
- last_dir_files_added = list()
- last_dir_files_removed = list()
+ last_dir_files_added = []
+ last_dir_files_removed = []
for row in ignorelist:
next_dir = row[0]
operand = row[1]
@@ -1347,8 +1347,8 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
if next_dir != last_dir:
self._done_dir_(last_dir, last_dir_files_added, last_dir_files_removed)
last_dir = next_dir
- last_dir_files_added = list()
- last_dir_files_removed = list()
+ last_dir_files_added = []
+ last_dir_files_removed = []
if operand == '|A|':
last_dir_files_added += [filename]
elif operand == '|R|':
diff --git a/pygnulib/GLMakefileTable.py b/pygnulib/GLMakefileTable.py
index ba63edb6cb..6568a19846 100644
--- a/pygnulib/GLMakefileTable.py
+++ b/pygnulib/GLMakefileTable.py
@@ -56,7 +56,7 @@ class GLMakefileTable(object):
raise TypeError('config must be a GLConfig, not %s'
% type(config).__name__)
self.config = config
- self.table = list()
+ self.table = []
def __getitem__(self, y: int) -> dict[str, bool]:
'''x.__getitem__(y) = x[y]'''
diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py
index f02f369f0e..bab143892f 100644
--- a/pygnulib/GLModuleSystem.py
+++ b/pygnulib/GLModuleSystem.py
@@ -737,10 +737,10 @@ class GLModuleTable(object):
self.dependers = dict() # Dependencies
self.conditionals = dict() # Conditional modules
self.unconditionals = dict() # Unconditional modules
- self.base_modules = list() # Base modules
- self.main_modules = list() # Main modules
- self.tests_modules = list() # Tests modules
- self.final_modules = list() # Final modules
+ self.base_modules = [] # Base modules
+ self.main_modules = [] # Main modules
+ self.tests_modules = [] # Tests modules
+ self.final_modules = [] # Final modules
if type(config) is not GLConfig:
raise TypeError('config must be a GLConfig, not %s'
% type(config).__name__)
@@ -752,7 +752,7 @@ class GLModuleTable(object):
% type(inc_all_direct_tests).__name__)
self.inc_all_direct_tests = inc_all_direct_tests
self.inc_all_indirect_tests = inc_all_indirect_tests
- self.avoids = list() # Avoids
+ self.avoids = [] # Avoids
for avoid in self.config.getAvoids():
module = self.modulesystem.find(avoid)
if module:
@@ -793,7 +793,7 @@ class GLModuleTable(object):
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)] = list()
+ self.dependers[str(module)] = []
if str(parent) not in self.dependers[str(module)]:
self.dependers[str(module)].append(str(parent))
key = '%s---%s' % (str(parent), str(module))
@@ -847,16 +847,16 @@ class GLModuleTable(object):
# module on the input list has been processed, it is added to the
# "handled list", so we can avoid to process it again.
inc_all_tests = self.inc_all_direct_tests
- handledmodules = list()
+ handledmodules = []
inmodules = modules
- outmodules = list()
+ outmodules = []
if self.config['conddeps']:
for module in modules:
if module not in self.avoids:
self.addUnconditional(module)
while inmodules:
inmodules_this_round = inmodules
- inmodules = list() # Accumulator, queue for next round
+ inmodules = [] # Accumulator, queue for next round
for module in inmodules_this_round:
if module not in self.avoids:
outmodules += [module]
@@ -1050,7 +1050,7 @@ class GLModuleTable(object):
def filelist(self, modules: list[GLModule]) -> list[str]:
'''Determine the final file list for the given list of modules.
The list of modules must already include dependencies.'''
- filelist = list()
+ filelist = []
for module in modules:
if type(module) is not GLModule:
raise TypeError('each module must be a GLModule instance')
diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py
index d292175de0..7ea1404e30 100644
--- a/pygnulib/GLTestDir.py
+++ b/pygnulib/GLTestDir.py
@@ -146,7 +146,7 @@ class GLTestDir(object):
sourcebase = self.config['sourcebase']
m4base = self.config['m4base']
testsbase = self.config['testsbase']
- result = list()
+ result = []
for file in files:
if file.startswith('build-aux/'):
path = constants.substart('build-aux/', '%s/' % auxdir, file)
@@ -353,7 +353,7 @@ class GLTestDir(object):
directories = sorted(set(directories))
# Copy files or make symbolic links or hard links.
- filetable = list()
+ filetable = []
for src in filelist:
dest = self.rewrite_files([src])[-1]
filetable += [tuple([dest, src])]
@@ -412,7 +412,7 @@ class GLTestDir(object):
file.write(emit)
subdirs = [sourcebase, m4base]
- subdirs_with_configure_ac = list()
+ subdirs_with_configure_ac = []
inctests = self.config.checkInclTestCategory(TESTS['tests'])
if inctests:
@@ -452,7 +452,7 @@ class GLTestDir(object):
emit += 'AC_PROG_INSTALL\n'
emit += 'AC_PROG_MAKE_SET\n'
emit += self.emitter.preEarlyMacros(False, '', modules)
- snippets = list()
+ snippets = []
for module in modules:
if str(module) in ['gnumakefile', 'maintainer-makefile']:
# These are meant to be used only in the top-level directory.
@@ -566,7 +566,7 @@ class GLTestDir(object):
emit += 'm4_pattern_allow([^gl_LIBOBJS$])dnl a variable\n'
emit += 'm4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable\n'
emit += self.emitter.preEarlyMacros(False, '', modules)
- snippets = list()
+ snippets = []
for module in final_modules:
if single_configure:
solution = True
@@ -753,7 +753,7 @@ class GLTestDir(object):
snippet = combine_lines(snippet)
# Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
- regex_find = list()
+ regex_find = []
pattern = re.compile(r'^CLEANFILES[\t ]*\+=(.*)$', re.M)
regex_find += pattern.findall(snippet)
pattern = re.compile(r'^MOSTLYCLEANFILES[\t ]*\+=(.*)$', re.M)
@@ -770,7 +770,7 @@ class GLTestDir(object):
# Extract the value of "BUILT_SOURCES += ...". Remove variable references
# such $(FOO_H) because they don't refer to distributed files.
- regex_find = list()
+ regex_find = []
pattern = re.compile(r'^BUILT_SOURCES[\t ]*\+=(.*)$', re.M)
regex_find += pattern.findall(snippet)
regex_find = [ line.strip()
@@ -798,7 +798,7 @@ class GLTestDir(object):
snippet = combine_lines(snippet)
# Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
- regex_find = list()
+ regex_find = []
pattern = re.compile(r'^CLEANFILES[\t ]*\+=(.*)$', re.M)
regex_find += pattern.findall(snippet)
pattern = re.compile(r'^MOSTLYCLEANFILES[\t ]*\+=(.*)$', re.M)
@@ -815,7 +815,7 @@ class GLTestDir(object):
# Extract the value of "BUILT_SOURCES += ...". Remove variable references
# such $(FOO_H) because they don't refer to distributed files.
- regex_find = list()
+ regex_find = []
pattern = re.compile(r'^BUILT_SOURCES[\t ]*\+=(.*)$', re.M)
regex_find += pattern.findall(snippet)
regex_find = [ line.strip()
@@ -914,7 +914,7 @@ class GLMegaTestDir(object):
auxdir = self.config['auxdir']
verbose = self.config['verbosity']
- megasubdirs = list()
+ megasubdirs = []
modules = [ self.modulesystem.find(m)
for m in self.config['modules'] ]
if not modules:
diff --git a/pygnulib/constants.py b/pygnulib/constants.py
index 506d9c31dc..7a88c21c39 100644
--- a/pygnulib/constants.py
+++ b/pygnulib/constants.py
@@ -35,7 +35,7 @@ import __main__ as interpreter
#===============================================================================
# Define module information
#===============================================================================
-__all__ = list()
+__all__ = []
__author__ = \
[
'Bruno Haible',
@@ -270,7 +270,7 @@ def joinpath(head: str, *tail: str) -> str:
'''Join two or more pathname components, inserting '/' as needed. If any
component is an absolute path, all previous path components will be
discarded.'''
- newtail = list()
+ newtail = []
for item in tail:
newtail += [item]
result = os.path.normpath(os.path.join(head, *tail))
@@ -459,7 +459,7 @@ def filter_filelist(separator: str, filelist: str, prefix: str, suffix: str,
prefix and ending with suffix are considered. Processing: removed_prefix
and removed_suffix are removed from each element, added_prefix and
added_suffix are added to each element.'''
- listing = list()
+ listing = []
for filename in filelist:
if filename.startswith(prefix) and filename.endswith(suffix):
pattern = re.compile(r'^%s(.*)%s$'
--
2.44.0