eric6/Utilities/ModuleParser.py

changeset 8207
d359172d11be
parent 8205
4a0f1f896341
child 8240
93b8a353c4bf
--- a/eric6/Utilities/ModuleParser.py	Fri Apr 09 18:13:36 2021 +0200
+++ b/eric6/Utilities/ModuleParser.py	Fri Apr 09 18:38:01 2021 +0200
@@ -349,7 +349,7 @@
 _modules = {}                           # cache of modules we've seen
 
 
-class VisibilityBase(object):
+class VisibilityBase:
     """
     Class implementing the visibility aspect of all objects.
     """
@@ -396,7 +396,7 @@
         self.visibility = 2
 
 
-class Module(object):
+class Module:
     """
     Class to represent a Python module.
     """
@@ -593,7 +593,7 @@
                     )
                 else:
                     meth_pyqtSig = None
-                lineno = lineno + src.count('\n', last_lineno_pos, start)
+                lineno += src.count('\n', last_lineno_pos, start)
                 last_lineno_pos = start
                 if modifierType and modifierIndent == thisindent:
                     if modifierType == "@staticmethod":
@@ -708,7 +708,7 @@
             elif m.start("Class") >= 0:
                 # we found a class definition
                 thisindent = _indent(m.group("ClassIndent"))
-                lineno = lineno + src.count('\n', last_lineno_pos, start)
+                lineno += src.count('\n', last_lineno_pos, start)
                 last_lineno_pos = start
                 # close all classes indented at least as much
                 while classstack and classstack[-1][1] >= thisindent:
@@ -772,7 +772,7 @@
                 classstack.append((cur_class, thisindent))
             
             elif m.start("Attribute") >= 0:
-                lineno = lineno + src.count('\n', last_lineno_pos, start)
+                lineno += src.count('\n', last_lineno_pos, start)
                 last_lineno_pos = start
                 index = -1
                 while index >= -len(classstack):
@@ -788,7 +788,7 @@
             
             elif m.start("Main") >= 0:
                 # 'main' part of the script, reset class stack
-                lineno = lineno + src.count('\n', last_lineno_pos, start)
+                lineno += src.count('\n', last_lineno_pos, start)
                 last_lineno_pos = start
                 classstack = []
             
@@ -796,7 +796,7 @@
                 thisindent = _indent(m.group("VariableIndent"))
                 variable_name = m.group("VariableName")
                 isSignal = m.group("VariableSignal") != ""
-                lineno = lineno + src.count('\n', last_lineno_pos, start)
+                lineno += src.count('\n', last_lineno_pos, start)
                 last_lineno_pos = start
                 if thisindent == 0:
                     # global variable
@@ -863,9 +863,8 @@
                 conditionalsstack.append(thisindent)
                 deltaindentcalculated = 0
             
-            elif m.start("Comment") >= 0:
-                if modulelevel:
-                    continue
+            elif m.start("Comment") >= 0 and modulelevel:
+                continue
             
             modulelevel = False
     
@@ -901,7 +900,7 @@
                 )
                 meth_sig = m.group("MethodSignature")
                 meth_sig = meth_sig and meth_sig.replace('\\\n', '') or ''
-                lineno = lineno + src.count('\n', last_lineno_pos, start)
+                lineno += src.count('\n', last_lineno_pos, start)
                 last_lineno_pos = start
                 if meth_name.startswith('self.'):
                     meth_name = meth_name[5:]
@@ -969,20 +968,11 @@
                 if cur_obj:
                     cur_obj.addDescription(contents)
             
-            elif m.start("String") >= 0:
-                pass
-            
-            elif m.start("Comment") >= 0:
-                pass
-            
-            elif m.start("ClassIgnored") >= 0:
-                pass
-            
             elif m.start("Class") >= 0:
                 # we found a class definition
                 thisindent = indent
                 indent += 1
-                lineno = lineno + src.count('\n', last_lineno_pos, start)
+                lineno += src.count('\n', last_lineno_pos, start)
                 last_lineno_pos = start
                 # close all classes/modules indented at least as much
                 while classstack and classstack[-1][1] >= thisindent:
@@ -1033,7 +1023,7 @@
                 # we found a module definition
                 thisindent = indent
                 indent += 1
-                lineno = lineno + src.count('\n', last_lineno_pos, start)
+                lineno += src.count('\n', last_lineno_pos, start)
                 last_lineno_pos = start
                 # close all classes/modules indented at least as much
                 while classstack and classstack[-1][1] >= thisindent:
@@ -1110,7 +1100,7 @@
                             index -= 1
 
             elif m.start("Attribute") >= 0:
-                lineno = lineno + src.count('\n', last_lineno_pos, start)
+                lineno += src.count('\n', last_lineno_pos, start)
                 last_lineno_pos = start
                 index = -1
                 while index >= -len(classstack):
@@ -1140,7 +1130,7 @@
                     lastGlobalEntry = None
             
             elif m.start("Attr") >= 0:
-                lineno = lineno + src.count('\n', last_lineno_pos, start)
+                lineno += src.count('\n', last_lineno_pos, start)
                 last_lineno_pos = start
                 index = -1
                 while index >= -len(classstack):
@@ -1206,7 +1196,12 @@
                     else:
                         indent = 0
             
-            elif m.start("BeginEnd") >= 0:
+            elif (
+                m.start("String") >= 0 or
+                m.start("Comment") >= 0 or
+                m.start("ClassIgnored") >= 0 or
+                m.start("BeginEnd") >= 0
+            ):
                 pass
     
     def createHierarchy(self):
@@ -1656,18 +1651,24 @@
                     pathname = os.path.join(p, name)
                     if ext == '.ptl':
                         # Quixote page template
-                        return (open(pathname), pathname,
-                        # __IGNORE_WARNING_Y115__
-                                ('.ptl', 'r', PTL_SOURCE))
+                        return (
+                            open(pathname), pathname,
+                            # __IGNORE_WARNING_Y115__
+                            ('.ptl', 'r', PTL_SOURCE)
+                        )
                     elif ext == '.rb':
                         # Ruby source file
-                        return (open(pathname), pathname,
-                        # __IGNORE_WARNING_Y115__
-                                ('.rb', 'r', RB_SOURCE))
+                        return (
+                            open(pathname), pathname,
+                            # __IGNORE_WARNING_Y115__
+                            ('.rb', 'r', RB_SOURCE)
+                        )
                     else:
-                        return (open(pathname), pathname,
-                        # __IGNORE_WARNING_Y115__
-                                (ext, 'r', PY_SOURCE))
+                        return (
+                            open(pathname), pathname,
+                            # __IGNORE_WARNING_Y115__
+                            (ext, 'r', PY_SOURCE)
+                        )
             raise ImportError
     
     # standard Python module file

eric ide

mercurial