changeset 8083:60e92a540ca7

chore: some ruff linter cleanups.
author John Rouillard <rouilj@ieee.org>
date Sun, 14 Jul 2024 12:42:07 -0400
parents a4127d7afaa9
children 2943140f5286
files roundup/pygettext.py
diffstat 1 files changed, 34 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/roundup/pygettext.py	Sat Jul 13 21:15:50 2024 -0400
+++ b/roundup/pygettext.py	Sun Jul 14 12:42:07 2024 -0400
@@ -23,6 +23,19 @@
 except ImportError:
     _ = lambda s: s
 
+import getopt
+import glob
+import importlib
+import operator
+import os
+import sys
+import time
+import token
+import tokenize
+from functools import reduce
+
+__version__ = '1.5'
+
 __doc__ = _("""pygettext -- Python equivalent of xgettext(1)
 
 Many systems (Solaris, Linux, Gnu) provide extensive tools that ease the
@@ -158,20 +171,6 @@
 If `inputfile' is -, standard input is read.
 """)
 
-import os
-import importlib
-import sys
-import glob
-import time
-import getopt
-import token
-import tokenize
-import operator
-
-from functools import reduce
-
-__version__ = '1.5'
-
 default_keywords = ['_']
 DEFAULTKEYWORDS = ', '.join(default_keywords)
 
@@ -199,6 +198,7 @@
 
 ''')
 
+
 def usage(code, msg=''):
     print(__doc__ % globals(), file=sys.stderr)
     if msg:
@@ -208,6 +208,7 @@
 
 escapes = []
 
+
 def make_escapes(pass_iso8859):
     global escapes
     escapes = [chr(i) for i in range(256)]
@@ -219,7 +220,7 @@
     else:
         mod = 256
     for i in range(mod):
-        if not(32 <= i <= 126):
+        if not (32 <= i <= 126):
             escapes[i] = "\\%03o" % i
     escapes[ord('\\')] = '\\\\'
     escapes[ord('\t')] = '\\t'
@@ -238,7 +239,7 @@
 
 def safe_eval(s):
     # unwrap quotes, safely
-    return eval(s, {'__builtins__':{}}, {})
+    return eval(s, {'__builtins__': {}}, {})
 
 
 def normalize(s):
@@ -257,9 +258,10 @@
         s = '""\n"' + lineterm.join(lines) + '"'
     return s
 
-def containsAny(str, set):
+
+def containsAny(string, inset):
     """Check whether 'str' contains ANY of the chars in 'set'"""
-    return 1 in [c in str for c in set]
+    return 1 in [c in string for c in inset]
 
 
 def _get_modpkg_path(dotted_name, pathlist=None):
@@ -270,11 +272,11 @@
     extension module.
     """
     pathname = None
-    r =  importlib.util.find_spec(dotted_name, pathlist)
+    r = importlib.util.find_spec(dotted_name, pathlist)
 
     if r.loader.is_package(dotted_name):
         pathname = r.submodule_search_locations[0]
-    elif issubclass(r.loader.__class__,(importlib.abc.SourceLoader)):
+    elif issubclass(r.loader.__class__, (importlib.abc.SourceLoader)):
         pathname = r.origin
     return pathname
 
@@ -287,10 +289,10 @@
         # check for glob chars
         if containsAny(name, "*?[]"):
             files = glob.glob(name)
-            list = []
+            lst = []
             for file in files:
-                list.extend(getFilesForName(file))
-            return list
+                lst.extend(getFilesForName(file))
+            return lst
 
         # try to find module or package
         name = _get_modpkg_path(name)
@@ -299,7 +301,7 @@
 
     if os.path.isdir(name):
         # find all python files in directory
-        list = []
+        lst = []
         # get extension for python source files
         if '_py_ext' not in globals():
             global _py_ext
@@ -309,17 +311,18 @@
             if 'CVS' in dirs:
                 dirs.remove('CVS')
             # add all *.py files to list
-            list.extend(
+            lst.extend(
                 [os.path.join(root, file) for file in files
                  if os.path.splitext(file)[1] == _py_ext]
                 )
-        return list
+        return lst
     elif os.path.exists(name):
         # a single file
         return [name]
 
     return []
 
+
 class TokenEater:
     def __init__(self, options):
         self.__options = options
@@ -398,14 +401,14 @@
                 ) % {
                 'token': tstring,
                 'file': self.__curfile,
-                'lineno': self.__lineno
+                'lineno': self.__lineno,
                 }, file=sys.stderr)
             self.__state = self.__waiting
 
     def __addentry(self, msg, lineno=None, isdocstring=0):
         if lineno is None:
             lineno = self.__lineno
-        if not msg in self.__options.toexclude:
+        if msg not in self.__options.toexclude:
             entry = (self.__curfile, lineno)
             self.__messages.setdefault(msg, {})[entry] = isdocstring
 
@@ -506,8 +509,8 @@
         nodocstrings = {}
 
     options = Options()
-    locations = {'gnu' : options.GNU,
-                 'solaris' : options.SOLARIS,
+    locations = {'gnu': options.GNU,
+                 'solaris': options.SOLARIS,
                  }
 
     # parse options
@@ -629,6 +632,7 @@
         if closep:
             fp.close()
 
+
 if __name__ == '__main__':
     main()
     # some more test strings

Roundup Issue Tracker: http://roundup-tracker.org/