]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Prefer 'list.append(item)' over 'list += [item]'.
authorCollin Funk <collin.funk1@gmail.com>
Mon, 8 Apr 2024 23:08:50 +0000 (16:08 -0700)
committerBruno Haible <bruno@clisp.org>
Tue, 9 Apr 2024 01:21:20 +0000 (03:21 +0200)
* pygnulib/*.py: Change occurrences '+= [item]' to use '.append(item)'
where item is a single element added to the list.
See discussion here:
<https://lists.gnu.org/archive/html/bug-gnulib/2024-04/msg00091.html>

ChangeLog
pygnulib/GLConfig.py
pygnulib/GLFileSystem.py
pygnulib/GLImport.py
pygnulib/GLMakefileTable.py
pygnulib/GLModuleSystem.py
pygnulib/GLTestDir.py
pygnulib/constants.py
pygnulib/main.py

index a6322054389ee2a123a98754f99f803343a9ceea..232070482a182deea0edbbe524429672ac1e01cf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-04-08  Collin Funk  <collin.funk1@gmail.com>
+
+       gnulib-tool.py: Prefer 'list.append(item)' over 'list += [item]'.
+       * pygnulib/*.py: Change occurrences '+= [item]' to use '.append(item)'
+       where item is a single element added to the list.
+       See discussion here:
+       <https://lists.gnu.org/archive/html/bug-gnulib/2024-04/msg00091.html>
+
 2024-04-08  Bruno Haible  <bruno@clisp.org>
 
        ptsname_r: Work around ptsname_r bug on NetBSD 10.0.
index 0f9d118a785ec6f120d08cc93814cb6b4854891e..571c22b8fcac6bf4c751352f745582ba2e3ff35a 100644 (file)
@@ -514,7 +514,7 @@ class GLConfig:
         '''Add the module to the modules list.'''
         if type(module) is str:
             if module not in self.table['modules']:
-                self.table['modules'] += [module]
+                self.table['modules'].append(module)
         else:  # if module has not str type
             raise TypeError('module must be a string, not %s'
                             % type(module).__name__)
index a463575f738df055da4d579a63b4df28b2eeb58c..810117ec4686972d0622c38c63040e471cb120c4 100644 (file)
@@ -226,7 +226,7 @@ class GLFileAssistant:
     def addFile(self, file: str) -> None:
         '''Add file to the list of added files.'''
         if file not in self.added:
-            self.added += [file]
+            self.added.append(file)
 
     def getFiles(self) -> list[str]:
         '''Return list of the added files.'''
index 08e83c5c9a41e226bc6d29391c17b62c0246c63c..b5f268af3dcfd5fffa09bf3c64c09d07c96abfa1 100644 (file)
@@ -335,7 +335,7 @@ class GLImport:
                 path = constants.substart('top/', '', file)
             else:  # file is not a special file
                 path = file
-            result += [os.path.normpath(path)]
+            result.append(os.path.normpath(path))
         return sorted(set(result))
 
     def rewrite_new_files(self, files: list[str]) -> list[str]:
@@ -371,7 +371,7 @@ class GLImport:
                 path = constants.substart('top/', '', file)
             else:  # file is not a special file
                 path = file
-            result += [os.path.normpath(path)]
+            result.append(os.path.normpath(path))
         return sorted(set(result))
 
     def actioncmd(self) -> str:
@@ -929,7 +929,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
         old_files = list(self.cache['files'])
         path = joinpath(destdir, m4base, 'gnulib-tool.m4')
         if isfile(path):
-            old_files += [joinpath('m4', 'gnulib-tool.m4')]
+            old_files.append(joinpath('m4', 'gnulib-tool.m4'))
 
         # Construct tables and transformers.
         transformers = dict()
@@ -941,10 +941,10 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
         new_table = []
         for src in old_files:
             dest = self.rewrite_old_files([src])[-1]
-            old_table += [tuple([dest, src])]
+            old_table.append(tuple([dest, src]))
         for src in new_files:
             dest = self.rewrite_new_files([src])[-1]
-            new_table += [tuple([dest, src])]
+            new_table.append(tuple([dest, src]))
         old_table = sorted(set(old_table))
         new_table = sorted(set(new_table))
 
@@ -997,14 +997,14 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
         # Create all necessary directories.
         dirs = [sourcebase, m4base]
         if pobase:
-            dirs += [pobase]
+            dirs.append(pobase)
         if [ file
              for file in filetable['all']
              if file.startswith('doc/') ]:
-            dirs += [docbase]
+            dirs.append(docbase)
         if gentests:
-            dirs += [testsbase]
-        dirs += [auxdir]
+            dirs.append(testsbase)
+        dirs.append(auxdir)
         dirs += sorted([ os.path.dirname(pair[0])
                          for pair in filetable['new'] ])
         dirs = [ os.path.join(destdir, d)
@@ -1044,7 +1044,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
                         raise GLError(14, file) from exc
                 else:  # if self.config['dryrun']
                     print('Remove file %s (backup in %s~)' % (path, path))
-                filetable['removed'] += [file]
+                filetable['removed'].append(file)
 
         # Files which are in filetable['new'] and not in filetable['old'].
         # They will be added/updated and added to filetable['added'] list.
@@ -1132,7 +1132,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
                         print('Creating %s' % filename)
                     else:  # if self.config['dryrun']:
                         print('Create %s' % filename)
-                    filetable['added'] += [filename]
+                    filetable['added'].append(filename)
                 if isfile(tmpfile):
                     os.remove(tmpfile)
 
@@ -1153,7 +1153,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
                     print('Creating %s' % filename)
                 else:  # if self.config['dryrun']:
                     print('Create %s' % filename)
-                filetable['added'] += [filename]
+                filetable['added'].append(filename)
             if isfile(tmpfile):
                 os.remove(tmpfile)
 
@@ -1174,7 +1174,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
                     print('Creating %s' % filename)
                 else:  # if self.config['dryrun']:
                     print('Create %s' % filename)
-                filetable['added'] += [filename]
+                filetable['added'].append(filename)
             if isfile(tmpfile):
                 os.remove(tmpfile)
 
@@ -1206,7 +1206,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
                     print('Updating %s (backup in %s)' % (filename, backup))
                 elif flag == 2:
                     print('Creating %s' % filename)
-                    filetable['added'] += [filename]
+                    filetable['added'].append(filename)
                 if isfile(tmpfile):
                     os.remove(tmpfile)
             else:  # if not self.config['dryrun']
@@ -1291,7 +1291,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
                 print('Creating %s' % filename)
             else:  # if self.config['dryrun']:
                 print('Create %s' % filename)
-            filetable['added'] += [filename]
+            filetable['added'].append(filename)
         if isfile(tmpfile):
             os.remove(tmpfile)
 
@@ -1315,7 +1315,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
                     print('Creating %s' % filename)
                 else:  # if self.config['dryrun']:
                     print('Create %s' % filename)
-                filetable['added'] += [filename]
+                filetable['added'].append(filename)
             if isfile(tmpfile):
                 os.remove(tmpfile)
 
@@ -1323,15 +1323,15 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
             # Update the .cvsignore and .gitignore files.
             ignorelist = []
             # Treat gnulib-comp.m4 like an added file, even if it already existed.
-            filetable['added'] += [joinpath(m4base, 'gnulib-comp.m4')]
+            filetable['added'].append(joinpath(m4base, 'gnulib-comp.m4'))
             filetable['added'] = sorted(set(filetable['added']))
             filetable['removed'] = sorted(set(filetable['removed']))
             for file in filetable['added']:
                 directory, basename = os.path.split(file)
-                ignorelist += [tuple([directory, '|A|', basename])]
+                ignorelist.append(tuple([directory, '|A|', basename]))
             for file in filetable['removed']:
                 directory, basename = os.path.split(file)
-                ignorelist += [tuple([directory, '|R|', basename])]
+                ignorelist.append(tuple([directory, '|R|', basename]))
             # Sort ignorelist by directory.
             ignorelist = sorted(ignorelist, key=lambda row: row[0])
             last_dir = ''
@@ -1347,9 +1347,9 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
                     last_dir_files_added = []
                     last_dir_files_removed = []
                 if operand == '|A|':
-                    last_dir_files_added += [filename]
+                    last_dir_files_added.append(filename)
                 elif operand == '|R|':
-                    last_dir_files_removed += [filename]
+                    last_dir_files_removed.append(filename)
             self._done_dir_(last_dir, last_dir_files_added, last_dir_files_removed)
 
         # Finish the work.
index 7547116f352365fe5eef1936940ba063fec3c8af..8df0822f00fcb33e21a278b17241390bd18ff42c 100644 (file)
@@ -83,7 +83,7 @@ class GLMakefileTable:
         if type(dotfirst) is not bool:
             raise TypeError('dotfirst must be a bool, not %s' % (type(dotfirst).__name__))
         dictionary = {'dir': dir, 'var': var, 'val': val, 'dotfirst': dotfirst}
-        self.table += [dictionary]
+        self.table.append(dictionary)
 
     def parent(self, gentests: bool, source_makefile_am: str, tests_makefile_am: str) -> None:
         '''Add a special row to Makefile.am table with the first parent directory
index 761c43c2e0ee0b3ce205807a714e53835ca6f50e..c2e20b801a11c87f5508cbcfbe63c37ef7e98c6d 100644 (file)
@@ -856,7 +856,7 @@ class GLModuleTable:
             inmodules = []               # Accumulator, queue for next round
             for module in inmodules_this_round:
                 if module not in self.avoids:
-                    outmodules += [module]
+                    outmodules.append(module)
                     if self.config['conddeps']:
                         conditional = self.isConditional(module)
                     dependencies = module.getDependenciesWithConditions()
@@ -878,8 +878,8 @@ class GLModuleTable:
                         testsname = module.getTestsName()
                         if self.modulesystem.exists(testsname):
                             testsmodule = self.modulesystem.find(testsname)
-                            depmodules += [testsmodule]
-                            conditions += [None]
+                            depmodules.append(testsmodule)
+                            conditions.append(None)
                     for depmodule in depmodules:
                         # Determine whether to include the dependency or tests module.
                         include = True
@@ -912,7 +912,7 @@ class GLModuleTable:
                                 if not inc_all_tests:
                                     include = False
                         if include and depmodule not in self.avoids:
-                            inmodules += [depmodule]
+                            inmodules.append(depmodule)
                             if self.config['conddeps']:
                                 index = depmodules.index(depmodule)
                                 condition = conditions[index]
@@ -1056,7 +1056,7 @@ class GLModuleTable:
         for listing in listings:
             for file in listing:
                 if file not in filelist:
-                    filelist += [file]
+                    filelist.append(file)
         return filelist
 
     def filelist_separately(self, main_modules: list[GLModule],
index 8defe52fc67f9aefb1e6827b6cbf5c37779a582b..9e071ace146d23a743e2a7a01ffe0d6b4fa102dd 100644 (file)
@@ -164,7 +164,7 @@ class GLTestDir:
                 path = constants.substart('top/', '', file)
             else:  # file is not a special file
                 path = file
-            result += [os.path.normpath(path)]
+            result.append(os.path.normpath(path))
         return sorted(set(result))
 
     def execute(self) -> None:
@@ -355,7 +355,7 @@ class GLTestDir:
         filetable = []
         for src in filelist:
             dest = self.rewrite_files([src])[-1]
-            filetable += [tuple([dest, src])]
+            filetable.append(tuple([dest, src]))
         for row in filetable:
             src = row[1]
             dest = row[0]
@@ -466,7 +466,7 @@ class GLTestDir:
                         pattern = re.compile(r'AC_REQUIRE\(\[([^()]*)\]\)', re.M)
                         snippet = pattern.sub(r'\1', snippet)
                         snippet = snippet.strip()
-                        snippets += [snippet]
+                        snippets.append(snippet)
                 snippets = [ snippet
                              for snippet in snippets
                              if snippet.strip()]
@@ -532,9 +532,9 @@ class GLTestDir:
                 # Restore changed variables.
                 self.config.setAuxDir(saved_auxdir)
                 auxdir = self.config['auxdir']
-                subdirs_with_configure_ac += [testsbase]
+                subdirs_with_configure_ac.append(testsbase)
 
-            subdirs += [testsbase]
+            subdirs.append(testsbase)
 
         # Create Makefile.am.
         emit = '## Process this file with automake to produce Makefile.in.\n\n'
@@ -580,7 +580,7 @@ class GLTestDir:
                 pattern = re.compile(r'AC_REQUIRE\(\[([^()]*)\]\)', re.M)
                 snippet = pattern.sub(r'\1', snippet)
                 snippet = snippet.strip()
-                snippets += [snippet]
+                snippets.append(snippet)
         snippets = [ snippet
                      for snippet in snippets
                      if snippet.strip() ]
@@ -659,7 +659,7 @@ class GLTestDir:
         for directory in subdirs:
             # For subdirs that have a configure.ac by their own, it's the subdir's
             # configure.ac which creates the subdir's Makefile.am, not this one.
-            makefiles += [joinpath(directory, 'Makefile')]
+            makefiles.append(joinpath(directory, 'Makefile'))
         if not single_configure:
             makefiles = makefiles[:-1]
         emit += 'AC_CONFIG_FILES([%s])\n' % ' '.join(makefiles)
@@ -926,7 +926,7 @@ class GLMegaTestDir:
         for module in modules:
             self.config.setModules([str(module)])
             GLTestDir(self.config, joinpath(self.megatestdir, str(module))).execute()
-            megasubdirs += [str(module)]
+            megasubdirs.append(str(module))
 
         # Then, all modules all together.
         # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
@@ -936,7 +936,7 @@ class GLMegaTestDir:
         self.config.setModules([ str(module)
                                  for module in modules ])
         GLTestDir(self.config, joinpath(self.megatestdir, 'ALL')).execute()
-        megasubdirs += ['ALL']
+        megasubdirs.append('ALL')
 
         # Create autobuild.
         emit = ''
index a07e47352904395bacb75b1e699a8e68bddc9f53..0a4f13b434096f9840ffcf26529c69dbd368dccf 100644 (file)
@@ -275,7 +275,7 @@ def joinpath(head: str, *tail: str) -> str:
     such as '$(srcdir)'.'''
     newtail = []
     for item in tail:
-        newtail += [item]
+        newtail.append(item)
     result = os.path.normpath(os.path.join(head, *tail))
     return result
 
@@ -469,7 +469,7 @@ def filter_filelist(separator: str, filelist: str, prefix: str, suffix: str,
                                  % (removed_prefix, removed_suffix))
             result = pattern.sub(r'%s\1%s'
                                  % (added_prefix, added_suffix), filename)
-            listing += [result]
+            listing.append(result)
     # Return an empty string if no files were matched, else combine them
     # with the given separator.
     if listing:
index a67252f7f6060fc73784b7562472b3ae29366645..151229489d5735c134c42935cd7d36d70871e381 100644 (file)
@@ -757,28 +757,28 @@ def main() -> None:
             inctests = True
     incl_test_categories = []
     if inctests:
-        incl_test_categories += [constants.TESTS['tests']]
+        incl_test_categories.append(constants.TESTS['tests'])
     if cmdargs.obsolete:
-        incl_test_categories += [constants.TESTS['obsolete']]
+        incl_test_categories.append(constants.TESTS['obsolete'])
     if cmdargs.inc_cxx_tests:
-        incl_test_categories += [constants.TESTS['cxx-tests']]
+        incl_test_categories.append(constants.TESTS['cxx-tests'])
     if cmdargs.inc_longrunning_tests:
-        incl_test_categories += [constants.TESTS['longrunning-tests']]
+        incl_test_categories.append(constants.TESTS['longrunning-tests'])
     if cmdargs.inc_privileged_tests:
-        incl_test_categories += [constants.TESTS['privileged-tests']]
+        incl_test_categories.append(constants.TESTS['privileged-tests'])
     if cmdargs.inc_unportable_tests:
-        incl_test_categories += [constants.TESTS['unportable-tests']]
+        incl_test_categories.append(constants.TESTS['unportable-tests'])
     if cmdargs.alltests:
-        incl_test_categories += [constants.TESTS['all-tests']]
+        incl_test_categories.append(constants.TESTS['all-tests'])
     excl_test_categories = []
     if cmdargs.excl_cxx_tests:
-        excl_test_categories += [constants.TESTS['cxx-tests']]
+        excl_test_categories.append(constants.TESTS['cxx-tests'])
     if cmdargs.excl_longrunning_tests:
-        excl_test_categories += [constants.TESTS['longrunning-tests']]
+        excl_test_categories.append(constants.TESTS['longrunning-tests'])
     if cmdargs.excl_privileged_tests:
-        excl_test_categories += [constants.TESTS['privileged-tests']]
+        excl_test_categories.append(constants.TESTS['privileged-tests'])
     if cmdargs.excl_unportable_tests:
-        excl_test_categories += [constants.TESTS['unportable-tests']]
+        excl_test_categories.append(constants.TESTS['unportable-tests'])
     lgpl = cmdargs.lgpl
     if lgpl != None:
         lgpl = lgpl[-1]
@@ -999,7 +999,7 @@ def main() -> None:
                             # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
                             if not isabs(aclocal_amflag):
                                 if isfile(joinpath(destdir, aclocal_amflag, 'gnulib-cache.m4')):
-                                    m4dirs += [aclocal_amflag]
+                                    m4dirs.append(aclocal_amflag)
                             dirisnext = False
                         else:  # if not dirisnext
                             if aclocal_amflag == '-I':
@@ -1010,7 +1010,7 @@ def main() -> None:
                         # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
                         if not isabs(arg):
                             if isfile(joinpath(destdir, arg, 'gnulib-cache.m4')):
-                                m4dirs += [arg]
+                                m4dirs.append(arg)
                 else:  # if not isfile(filepath)
                     # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
                     filepath = joinpath(destdir, 'aclocal.m4')