diff -r aff39db4dacc -r 7c017076c12e eric6/Utilities/ModuleParser.py --- a/eric6/Utilities/ModuleParser.py Mon Sep 23 19:10:42 2019 +0200 +++ b/eric6/Utilities/ModuleParser.py Mon Sep 23 19:22:12 2019 +0200 @@ -555,11 +555,13 @@ meth_ret = m.group("MethodReturnAnnotation") meth_ret = meth_ret.replace('\\\n', '') if m.group("MethodPyQtSignature") is not None: - meth_pyqtSig = m.group("MethodPyQtSignature")\ - .replace('\\\n', '')\ - .split('result')[0]\ - .split('name')[0]\ - .strip("\"', \t") + meth_pyqtSig = ( + m.group("MethodPyQtSignature") + .replace('\\\n', '') + .split('result')[0] + .split('name')[0] + .strip("\"', \t") + ) else: meth_pyqtSig = None lineno = lineno + src.count('\n', last_lineno_pos, start) @@ -584,17 +586,20 @@ deltaindentcalculated = 1 thisindent -= deltaindent else: - while conditionalsstack and \ - conditionalsstack[-1] >= thisindent: + while ( + conditionalsstack and + conditionalsstack[-1] >= thisindent + ): del conditionalsstack[-1] if deltastack: del deltastack[-1] deltaindentcalculated = 0 # close all classes indented at least as much - while classstack and \ - classstack[-1][1] >= thisindent: - if classstack[-1][0] is not None and \ - isinstance(classstack[-1][0], (Class, Function)): + while classstack and classstack[-1][1] >= thisindent: + if ( + classstack[-1][0] is not None and + isinstance(classstack[-1][0], (Class, Function)) + ): # record the end line of this class or function classstack[-1][0].setEndLine(lineno - 1) del classstack[-1] @@ -652,16 +657,21 @@ if self.file.lower().endswith('.ptl'): contents = "" else: - contents = m.group("DocstringContents1") \ - or m.group("DocstringContents2") + contents = ( + m.group("DocstringContents1") or + m.group("DocstringContents2") + ) if cur_obj: cur_obj.addDescription(contents) elif m.start("String") >= 0: - if modulelevel and \ - (src[start - len('\r\n'):start] == '\r\n' or - src[start - len('\n'):start] == '\n' or - src[start - len('\r'):start] == '\r'): + if ( + modulelevel and ( + src[start - len('\r\n'):start] == '\r\n' or + src[start - len('\n'):start] == '\n' or + src[start - len('\r'):start] == '\r' + ) + ): contents = m.group("StringContents3") if contents is not None: contents = _hashsub(r"\1", contents) @@ -669,8 +679,10 @@ if self.file.lower().endswith('.ptl'): contents = "" else: - contents = m.group("StringContents1") \ - or m.group("StringContents2") + contents = ( + m.group("StringContents1") or + m.group("StringContents2") + ) if cur_obj: cur_obj.addDescription(contents) @@ -680,10 +692,11 @@ lineno = 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: - if classstack[-1][0] is not None and \ - isinstance(classstack[-1][0], (Class, Function)): + while classstack and classstack[-1][1] >= thisindent: + if ( + classstack[-1][0] is not None and + isinstance(classstack[-1][0], (Class, Function)) + ): # record the end line of this class or function classstack[-1][0].setEndLine(lineno - 1) del classstack[-1] @@ -769,8 +782,10 @@ if classstack[index][1] >= thisindent: index -= 1 else: - if classstack[index][0] is not None and \ - isinstance(classstack[index][0], Class): + if ( + classstack[index][0] is not None and + isinstance(classstack[index][0], Class) + ): attr = Attribute( self.name, variable_name, self.file, lineno, isSignal=isSignal) @@ -809,8 +824,10 @@ elif m.start("ConditionalDefine") >= 0: # a conditional function/method definition thisindent = _indent(m.group("ConditionalDefineIndent")) - while conditionalsstack and \ - conditionalsstack[-1] >= thisindent: + while ( + conditionalsstack and + conditionalsstack[-1] >= thisindent + ): del conditionalsstack[-1] if deltastack: del deltastack[-1] @@ -850,9 +867,11 @@ # found a method definition or function thisindent = indent indent += 1 - meth_name = m.group("MethodName") or \ - m.group("MethodName2") or \ + meth_name = ( + m.group("MethodName") or + m.group("MethodName2") or m.group("MethodName3") + ) meth_sig = m.group("MethodSignature") meth_sig = meth_sig and meth_sig.replace('\\\n', '') or '' lineno = lineno + src.count('\n', last_lineno_pos, start) @@ -862,16 +881,16 @@ elif meth_name.startswith('self::'): meth_name = meth_name[6:] # close all classes/modules indented at least as much - while classstack and \ - classstack[-1][1] >= thisindent: - if classstack[-1][0] is not None and \ - isinstance(classstack[-1][0], - (Class, Function, RbModule)): + while classstack and classstack[-1][1] >= thisindent: + if ( + classstack[-1][0] is not None and + isinstance(classstack[-1][0], + (Class, Function, RbModule)) + ): # record the end line of this class, function or module classstack[-1][0].setEndLine(lineno - 1) del classstack[-1] - while acstack and \ - acstack[-1][1] >= thisindent: + while acstack and acstack[-1][1] >= thisindent: del acstack[-1] if classstack: csi = -1 @@ -882,8 +901,10 @@ if cur_class is None: continue - if isinstance(cur_class, Class) or \ - isinstance(cur_class, RbModule): + if ( + isinstance(cur_class, Class) or + isinstance(cur_class, RbModule) + ): # it's a class/module method f = Function(None, meth_name, None, lineno, meth_sig) @@ -940,11 +961,12 @@ lineno = 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: - if classstack[-1][0] is not None and \ - isinstance(classstack[-1][0], - (Class, Function, RbModule)): + while classstack and classstack[-1][1] >= thisindent: + if ( + classstack[-1][0] is not None and + isinstance(classstack[-1][0], + (Class, Function, RbModule)) + ): # record the end line of this class, function or module classstack[-1][0].setEndLine(lineno - 1) del classstack[-1] @@ -964,9 +986,11 @@ parent_obj = self if class_name in parent_obj.classes: cur_class = parent_obj.classes[class_name] - elif classstack and \ - isinstance(classstack[-1][0], Class) and \ - class_name == "self": + elif ( + classstack and + isinstance(classstack[-1][0], Class) and + class_name == "self" + ): cur_class = classstack[-1][0] else: parent_obj.addClass(class_name, cur_class) @@ -976,8 +1000,7 @@ lastGlobalEntry = cur_class cur_obj = cur_class classstack.append((cur_class, thisindent)) - while acstack and \ - acstack[-1][1] >= thisindent: + while acstack and acstack[-1][1] >= thisindent: del acstack[-1] acstack.append(["public", thisindent]) # default access control is 'public' @@ -989,11 +1012,12 @@ lineno = 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: - if classstack[-1][0] is not None and \ - isinstance(classstack[-1][0], - (Class, Function, RbModule)): + while classstack and classstack[-1][1] >= thisindent: + if ( + classstack[-1][0] is not None and + isinstance(classstack[-1][0], + (Class, Function, RbModule)) + ): # record the end line of this class, function or module classstack[-1][0].setEndLine(lineno - 1) del classstack[-1] @@ -1012,8 +1036,7 @@ lastGlobalEntry = cur_class cur_obj = cur_class classstack.append((cur_class, thisindent)) - while acstack and \ - acstack[-1][1] >= thisindent: + while acstack and acstack[-1][1] >= thisindent: del acstack[-1] acstack.append(["public", thisindent]) # default access control is 'public' @@ -1024,9 +1047,10 @@ index = -1 while index >= -len(acstack): if acstack[index][1] < indent: - actype = \ - m.group("AccessControlType") or \ + actype = ( + m.group("AccessControlType") or m.group("AccessControlType2").split('_')[0] + ) acstack[index][0] = actype.lower() break else: @@ -1034,13 +1058,16 @@ else: index = -1 while index >= -len(classstack): - if classstack[index][0] is not None and \ - not isinstance(classstack[index][0], Function) and \ - not classstack[index][1] >= indent: + if ( + classstack[index][0] is not None and + not isinstance(classstack[index][0], Function) and + not classstack[index][1] >= indent + ): parent = classstack[index][0] - actype = \ - m.group("AccessControlType") or \ + actype = ( + m.group("AccessControlType") or m.group("AccessControlType2").split('_')[0] + ) actype = actype.lower() for name in aclist.split(","): # get rid of leading ':' @@ -1063,9 +1090,11 @@ last_lineno_pos = start index = -1 while index >= -len(classstack): - if classstack[index][0] is not None and \ - not isinstance(classstack[index][0], Function) and \ - not classstack[index][1] >= indent: + if ( + classstack[index][0] is not None and + not isinstance(classstack[index][0], Function) and + not classstack[index][1] >= indent + ): attrName = m.group("AttributeName") attr = Attribute( self.name, attrName, self.file, lineno) @@ -1091,9 +1120,11 @@ last_lineno_pos = start index = -1 while index >= -len(classstack): - if classstack[index][0] is not None and \ - not isinstance(classstack[index][0], Function) and \ - not classstack[index][1] >= indent: + if ( + classstack[index][0] is not None and + not isinstance(classstack[index][0], Function) and + not classstack[index][1] >= indent + ): parent = classstack[index][0] if m.group("AttrType") is None: nv = m.group("AttrList").split(",") @@ -1101,10 +1132,12 @@ break # get rid of leading ':' name = nv[0].strip()[1:] - attr = parent.getAttribute("@" + name) or \ - parent.getAttribute("@@" + name) or \ + attr = ( + parent.getAttribute("@" + name) or + parent.getAttribute("@@" + name) or Attribute( self.name, "@" + name, self.file, lineno) + ) if len(nv) == 1 or nv[1].strip() == "false": attr.setProtected() elif nv[1].strip() == "true": @@ -1115,15 +1148,19 @@ for name in m.group("AttrList").split(","): # get rid of leading ':' name = name.strip()[1:] - attr = parent.getAttribute("@" + name) or \ - parent.getAttribute("@@" + name) or \ + attr = ( + parent.getAttribute("@" + name) or + parent.getAttribute("@@" + name) or Attribute( self.name, "@" + name, self.file, lineno) + ) if access == "_accessor": attr.setPublic() - elif access == "_reader" or \ - access == "_writer": + elif ( + access == "_reader" or + access == "_writer" + ): if attr.isPrivate(): attr.setProtected() elif attr.isProtected(): @@ -1508,9 +1545,11 @@ path = [os.path.dirname(module)] if module.lower().endswith(".py"): module = module[:-3] - if os.path.exists(os.path.join(path[0], "__init__.py")) or \ - os.path.exists(os.path.join(path[0], "__init__.rb")) or \ - inpackage: + if ( + os.path.exists(os.path.join(path[0], "__init__.py")) or + os.path.exists(os.path.join(path[0], "__init__.rb")) or + inpackage + ): if basename: module = module.replace(basename, "") if os.path.isabs(module): @@ -1648,8 +1687,10 @@ modname = module.replace(os.sep, '.') else: modname = os.path.basename(module) - if modname.lower().endswith(".ptl") or \ - modname.lower().endswith(".pyw"): + if ( + modname.lower().endswith(".ptl") or + modname.lower().endswith(".pyw") + ): modname = modname[:-4] elif modname.lower().endswith(".rb"): modname = modname[:-3]