Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
codefactor: fix use len(Seq) to determine Seq is empty issue
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 18 Dec 2019 08:53:27 +0000 (09:53 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 18 Dec 2019 08:53:27 +0000 (09:53 +0100)
docs/source/_ext/autodoxy.py
src/simix/simcalls.py
tools/tesh/tesh.py

index c82d0fd..00720cb 100644 (file)
@@ -363,7 +363,7 @@ class DoxygenMethodDocumenter(DoxygenDocumenter):
     def parse_id(self, id):
         xp = './/*[@id="%s"]' % id
         match = get_doxygen_root().xpath(xp)
     def parse_id(self, id):
         xp = './/*[@id="%s"]' % id
         match = get_doxygen_root().xpath(xp)
-        if len(match) > 0:
+        if match:
             match = match[0]
             self.fullname = match.find('./definition').text.split()[-1]
             self.modname = self.fullname
             match = match[0]
             self.fullname = match.find('./definition').text.split()[-1]
             self.modname = self.fullname
@@ -390,7 +390,7 @@ class DoxygenMethodDocumenter(DoxygenDocumenter):
         else:
             xpath_query = xpath_query_noparam
         match = get_doxygen_root().xpath(xpath_query)
         else:
             xpath_query = xpath_query_noparam
         match = get_doxygen_root().xpath(xpath_query)
-        if len(match) == 0:
+        if not match:
             logger = logging.getLogger(__name__)
 
             if self.argsstring != None:
             logger = logging.getLogger(__name__)
 
             if self.argsstring != None:
@@ -438,7 +438,7 @@ class DoxygenMethodDocumenter(DoxygenDocumenter):
 
     def format_template_name(self):
         types = [e.text for e in self.object.findall('templateparamlist/param/type')]
 
     def format_template_name(self):
         types = [e.text for e in self.object.findall('templateparamlist/param/type')]
-        if len(types) == 0:
+        if not types:
             return ''
         ret = 'template <%s>' % ','.join(types)
 #        print ("template: {}".format(ret))
             return ''
         ret = 'template <%s>' % ','.join(types)
 #        print ("template: {}".format(ret))
@@ -476,7 +476,7 @@ class DoxygenVariableDocumenter(DoxygenDocumenter):
                        '/memberdef[@kind="variable"]/name[text()="{:s}"]/..').format(obj, var)
 #        print("fullname {}".format(self.fullname))
         match = get_doxygen_root().xpath(xpath_query)
                        '/memberdef[@kind="variable"]/name[text()="{:s}"]/..').format(obj, var)
 #        print("fullname {}".format(self.fullname))
         match = get_doxygen_root().xpath(xpath_query)
-        if len(match) == 0:
+        if not match:
             logger = logging.getLogger(__name__)
 
             logger.warning("[autodoxy] WARNING: could not find variable {}::{} in Doxygen files".format(obj, var))
             logger = logging.getLogger(__name__)
 
             logger.warning("[autodoxy] WARNING: could not find variable {}::{} in Doxygen files".format(obj, var))
@@ -487,7 +487,7 @@ class DoxygenVariableDocumenter(DoxygenDocumenter):
     def parse_id(self, id):
         xp = './/*[@id="%s"]' % id
         match = get_doxygen_root().xpath(xp)
     def parse_id(self, id):
         xp = './/*[@id="%s"]' % id
         match = get_doxygen_root().xpath(xp)
-        if len(match) > 0:
+        if match:
             match = match[0]
             self.fullname = match.find('./definition').text.split()[-1]
             self.modname = self.fullname
             match = match[0]
             self.fullname = match.find('./definition').text.split()[-1]
             self.modname = self.fullname
@@ -524,7 +524,7 @@ class DoxygenVariableDocumenter(DoxygenDocumenter):
 
     def format_template_name(self):
         types = [e.text for e in self.object.findall('templateparamlist/param/type')]
 
     def format_template_name(self):
         types = [e.text for e in self.object.findall('templateparamlist/param/type')]
-        if len(types) == 0:
+        if not types:
             return ''
         ret = 'template <%s>' % ','.join(types)
 #        print ("template: {}".format(ret))
             return ''
         ret = 'template <%s>' % ','.join(types)
 #        print ("template: {}".format(ret))
@@ -551,7 +551,7 @@ def set_doxygen_xml(app):
     files = [os.path.join(app.config.doxygen_xml, f)
              for f in os.listdir(app.config.doxygen_xml)
              if f.lower().endswith('.xml') and not f.startswith('._')]
     files = [os.path.join(app.config.doxygen_xml, f)
              for f in os.listdir(app.config.doxygen_xml)
              if f.lower().endswith('.xml') and not f.startswith('._')]
-    if len(files) == 0:
+    if not files:
         raise err
 
     setup.DOXYGEN_ROOT = ET.ElementTree(ET.Element('root')).getroot()
         raise err
 
     setup.DOXYGEN_ROOT = ET.ElementTree(ET.Element('root')).getroot()
index c982a24..3ce600d 100755 (executable)
@@ -135,7 +135,7 @@ class Simcall(object):
         res.append(indent + 'case SIMCALL_%s:' % (self.name.upper()))
         if self.need_handler:
             call = "simcall_HANDLER_%s(&simcall%s%s)" % (self.name,
         res.append(indent + 'case SIMCALL_%s:' % (self.name.upper()))
         if self.need_handler:
             call = "simcall_HANDLER_%s(&simcall%s%s)" % (self.name,
-                                                        ", " if len(args) > 0 else "",
+                                                        ", " if args else "",
                                                         ', '.join(args))
         else:
             call = "SIMIX_%s(%s)" % (self.name, ', '.join(args))
                                                         ', '.join(args))
         else:
             call = "SIMIX_%s(%s)" % (self.name, ', '.join(args))
index ea8f485..e392be7 100755 (executable)
@@ -10,7 +10,6 @@ Copyright (c) 2012-2019. The SimGrid Team. All rights reserved.
 This program is free software; you can redistribute it and/or modify it
 under the terms of the license (GNU LGPL) which comes with this package.
 
 This program is free software; you can redistribute it and/or modify it
 under the terms of the license (GNU LGPL) which comes with this package.
 
-
 #TODO: child of child of child that printfs. Does it work?
 #TODO: a child dies after its parent. What happen?
 
 #TODO: child of child of child that printfs. Does it work?
 #TODO: a child dies after its parent. What happen?
 
@@ -25,7 +24,6 @@ under the terms of the license (GNU LGPL) which comes with this package.
 
 """
 
 
 """
 
-
 import sys
 import os
 import shlex
 import sys
 import os
 import shlex
@@ -47,14 +45,12 @@ else:
 #
 #
 
 #
 #
 
-
 def isWindows():
     return sys.platform.startswith('win')
 
 # Singleton metaclass that works in Python 2 & 3
 # http://stackoverflow.com/questions/6760685/creating-a-singleton-in-python
 
 def isWindows():
     return sys.platform.startswith('win')
 
 # Singleton metaclass that works in Python 2 & 3
 # http://stackoverflow.com/questions/6760685/creating-a-singleton-in-python
 
-
 class _Singleton(type):
     """ A metaclass that creates a Singleton base class when called. """
     _instances = {}
 class _Singleton(type):
     """ A metaclass that creates a Singleton base class when called. """
     _instances = {}
@@ -64,11 +60,9 @@ class _Singleton(type):
             cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
         return cls._instances[cls]
 
             cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
         return cls._instances[cls]
 
-
 class Singleton(_Singleton('SingletonMeta', (object,), {})):
     pass
 
 class Singleton(_Singleton('SingletonMeta', (object,), {})):
     pass
 
-
 SIGNALS_TO_NAMES_DICT = dict((getattr(signal, n), n)
                              for n in dir(signal) if n.startswith('SIG') and '_' not in n)
 
 SIGNALS_TO_NAMES_DICT = dict((getattr(signal, n), n)
                              for n in dir(signal) if n.startswith('SIG') and '_' not in n)
 
@@ -427,7 +421,7 @@ class Cmd(object):
             logs.append("(ignoring the output of <{cmd}> as requested)".format(cmd=cmdName))
         else:
             stdouta = stdout_data.split("\n")
             logs.append("(ignoring the output of <{cmd}> as requested)".format(cmd=cmdName))
         else:
             stdouta = stdout_data.split("\n")
-            while len(stdouta) > 0 and stdouta[-1] == "":
+            while stdouta and stdouta[-1] == "":
                 del stdouta[-1]
             stdouta = self.remove_ignored_lines(stdouta)
             stdcpy = stdouta[:]
                 del stdouta[-1]
             stdouta = self.remove_ignored_lines(stdouta)
             stdcpy = stdouta[:]
@@ -447,7 +441,7 @@ class Cmd(object):
                     lineterm="",
                     fromfile='expected',
                     tofile='obtained'))
                     lineterm="",
                     fromfile='expected',
                     tofile='obtained'))
-            if len(diff) > 0:
+            if diff:
                 logs.append("Output of <{cmd}> mismatch:".format(cmd=cmdName))
                 if self.sort >= 0:  # If sorted, truncate the diff output and show the unsorted version
                     difflen = 0
                 logs.append("Output of <{cmd}> mismatch:".format(cmd=cmdName))
                 if self.sort >= 0:  # If sorted, truncate the diff output and show the unsorted version
                     difflen = 0
@@ -471,7 +465,7 @@ class Cmd(object):
                 if TeshState().keep:
                     f = open('obtained', 'w')
                     obtained = stdout_data.split("\n")
                 if TeshState().keep:
                     f = open('obtained', 'w')
                     obtained = stdout_data.split("\n")
-                    while len(obtained) > 0 and obtained[-1] == "":
+                    while obtained and obtained[-1] == "":
                         del obtained[-1]
                     obtained = self.remove_ignored_lines(obtained)
                     for line in obtained:
                         del obtained[-1]
                     obtained = self.remove_ignored_lines(obtained)
                     for line in obtained:
@@ -514,14 +508,12 @@ class Cmd(object):
     def can_run(self):
         return self.args is not None
 
     def can_run(self):
         return self.args is not None
 
-
 ##############
 #
 # Main
 #
 #
 
 ##############
 #
 # Main
 #
 #
 
-
 if __name__ == '__main__':
     signal.signal(signal.SIGINT, signal_handler)
     signal.signal(signal.SIGTERM, signal_handler)
 if __name__ == '__main__':
     signal.signal(signal.SIGINT, signal_handler)
     signal.signal(signal.SIGTERM, signal_handler)
@@ -609,7 +601,7 @@ if __name__ == '__main__':
     line = f.readfullline()
     while line is not None:
         # print(">>============="+line+"==<<")
     line = f.readfullline()
     while line is not None:
         # print(">>============="+line+"==<<")
-        if len(line) == 0:
+        if not line:
             #print ("END CMD block")
             if cmd.run_if_possible():
                 cmd = Cmd()
             #print ("END CMD block")
             if cmd.run_if_possible():
                 cmd = Cmd()