eric6/DocumentationTools/ModuleDocumentor.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8043
0acf98cd089a
parent 8257
28146736bbfc
--- a/eric6/DocumentationTools/ModuleDocumentor.py	Fri Apr 02 11:59:41 2021 +0200
+++ b/eric6/DocumentationTools/ModuleDocumentor.py	Sat May 01 14:27:20 2021 +0200
@@ -13,6 +13,7 @@
 
 import sys
 import re
+import contextlib
 
 from Utilities import html_uencode
 from Utilities.ModuleParser import RB_SOURCE, Function
@@ -55,7 +56,7 @@
     pass
 
 
-class ModuleDocument(object):
+class ModuleDocument:
     """
     Class implementing the builtin documentation generator.
     """
@@ -303,10 +304,11 @@
             
         classesSection = self.__genClassesSection()
         functionsSection = self.__genFunctionsSection()
-        if self.module.type == RB_SOURCE:
-            rbModulesSection = self.__genRbModulesSection()
-        else:
-            rbModulesSection = ""
+        rbModulesSection = (
+            self.__genRbModulesSection()
+            if self.module.type == RB_SOURCE else
+            ""
+        )
         return "{0}{1}{2}{3}".format(
             modBody, classesSection, rbModulesSection, functionsSection)
         
@@ -331,10 +333,8 @@
                     self.__checkDeprecated(sectionDict[name].description) and
                     self.listEntryDeprecatedTemplate or "",
                    }))
-            if kwSuffix:
-                n = "{0} ({1})".format(name, kwSuffix)
-            else:
-                n = "{0}".format(name)
+            n = ("{0} ({1})".format(name, kwSuffix) if kwSuffix
+                 else "{0}".format(name))
             self.keywords.append((n, "#{0}".format(name)))
         return ''.join(lst)
         
@@ -347,18 +347,16 @@
         @return The globals list section. (string)
         """
         attrNames = []
-        if class_ is not None:
-            scope = class_
-        else:
-            scope = self.module
+        scope = class_ if class_ is not None else self.module
         attrNames = sorted(attr for attr in scope.globals.keys()
                            if not scope.globals[attr].isSignal)
-        if attrNames:
-            s = ''.join(
+        s = (
+            ''.join(
                 [self.listEntrySimpleTemplate.format(**{'Name': name})
                  for name in attrNames])
-        else:
-            s = self.listEntryNoneTemplate
+            if attrNames else
+            self.listEntryNoneTemplate
+        )
         return self.listTemplate.format(**{'Entries': s})
         
     def __genClassListSection(self):
@@ -418,10 +416,7 @@
         for className in classNames:
             _class = self.module.classes[className]
             supers = _class.super
-            if len(supers) > 0:
-                supers = ', '.join(supers)
-            else:
-                supers = 'None'
+            supers = ', '.join(supers) if len(supers) > 0 else "None"
             
             globalsList = self.__genGlobalsListSection(_class)
             classMethList, classMethBodies = self.__genMethodSection(
@@ -474,7 +469,7 @@
         """
         lst = []
         if includeInit:
-            try:
+            with contextlib.suppress(KeyError):
                 lst.append(self.listEntryTemplate.format(
                     **{'Link': "{0}.{1}".format(className, '__init__'),
                        'Name': clsName,
@@ -487,8 +482,6 @@
                 self.keywords.append(
                     ("{0} (Constructor)".format(className),
                      "#{0}.{1}".format(className, '__init__')))
-            except KeyError:
-                pass
         
         for name in names:
             lst.append(self.listEntryTemplate.format(
@@ -633,10 +626,7 @@
         for className in classNames:
             _class = obj.classes[className]
             supers = _class.super
-            if len(supers) > 0:
-                supers = ', '.join(supers)
-            else:
-                supers = 'None'
+            supers = ', '.join(supers) if len(supers) > 0 else "None"
             
             methList, methBodies = self.__genMethodSection(
                 _class, className, Function.General)
@@ -1167,87 +1157,96 @@
             elif not inTagSection:
                 lastItem.append(ditem)
         
-        if paragraphs:
-            description = self.__genParagraphs(paragraphs)
-        else:
-            description = ""
+        description = self.__genParagraphs(paragraphs) if paragraphs else ""
         
-        if paramList:
-            parameterSect = self.parametersListTemplate.format(
+        parameterSect = (
+            self.parametersListTemplate.format(
                 **{'Parameters': self.__genParamDescriptionListSection(
                     paramList)})
-        else:
-            parameterSect = ""
+            if paramList else
+            ""
+        )
         
-        if returns:
-            returnSect = self.returnsTemplate.format(
+        returnSect = (
+            self.returnsTemplate.format(
                 html_uencode('\n'.join(returns)))
-        else:
-            returnSect = ""
-        
-        if returnTypes:
-            returnTypesSect = self.returnTypesTemplate.format(
-                html_uencode('\n'.join(returnTypes)))
-        else:
-            returnTypesSect = ""
+            if returns else
+            ""
+        )
         
-        if yields:
-            yieldSect = self.yieldsTemplate.format(
-                html_uencode('\n'.join(yields)))
-        else:
-            yieldSect = ""
+        returnTypesSect = (
+            self.returnTypesTemplate.format(
+                html_uencode('\n'.join(returnTypes)))
+            if returnTypes else
+            ""
+        )
         
-        if yieldTypes:
-            yieldTypesSect = self.yieldTypesTemplate.format(
+        yieldSect = (
+            self.yieldsTemplate.format(
+                html_uencode('\n'.join(yields)))
+            if yields else
+            ""
+        )
+        
+        yieldTypesSect = (
+            self.yieldTypesTemplate.format(
                 html_uencode('\n'.join(yieldTypes)))
-        else:
-            yieldTypesSect = ""
+            if yieldTypes else
+            ""
+        )
         
-        if exceptionDict:
-            exceptionSect = self.exceptionsListTemplate.format(
+        exceptionSect = (
+            self.exceptionsListTemplate.format(
                 **{'Exceptions': self.__genDescriptionListSection(
                     exceptionDict, self.exceptionsListEntryTemplate)})
-        else:
-            exceptionSect = ""
+            if exceptionDict else
+            ""
+        )
         
-        if signalDict:
-            signalSect = self.signalsListTemplate.format(
+        signalSect = (
+            self.signalsListTemplate.format(
                 **{'Signals': self.__genDescriptionListSection(
                     signalDict, self.signalsListEntryTemplate)})
-        else:
-            signalSect = ""
+            if signalDict else
+            ""
+        )
         
-        if eventDict:
-            eventSect = self.eventsListTemplate.format(
+        eventSect = (
+            self.eventsListTemplate.format(
                 **{'Events': self.__genDescriptionListSection(
                     eventDict, self.eventsListEntryTemplate)})
-        else:
-            eventSect = ""
+            if eventDict else
+            ""
+        )
         
-        if deprecated:
-            deprecatedSect = self.deprecatedTemplate.format(
+        deprecatedSect = (
+            self.deprecatedTemplate.format(
                 **{'Lines': html_uencode('\n'.join(deprecated))})
-        else:
-            deprecatedSect = ""
+            if deprecated else
+            ""
+        )
         
-        if authorInfo:
-            authorInfoSect = self.authorInfoTemplate.format(
+        authorInfoSect = (
+            self.authorInfoTemplate.format(
                 **{'Authors': html_uencode('\n'.join(authorInfo))})
-        else:
-            authorInfoSect = ""
+            if authorInfo else
+            ""
+        )
         
-        if sinceInfo:
-            sinceInfoSect = self.sinceInfoTemplate.format(
+        sinceInfoSect = (
+            self.sinceInfoTemplate.format(
                 **{'Info': html_uencode(sinceInfo[0])})
-        else:
-            sinceInfoSect = ""
+            if sinceInfo else
+            ""
+        )
         
-        if seeList:
-            seeSect = self.seeListTemplate.format(
+        seeSect = (
+            self.seeListTemplate.format(
                 **{'Links': self.__genSeeListSection(
                     seeList, self.seeListEntryTemplate)})
-        else:
-            seeSect = ''
+            if seeList else
+            ''
+        )
         
         return "".join([
             deprecatedSect, description, parameterSect, returnSect,

eric ide

mercurial