diff -r e9e7eca7efee -r bf71ee032bb4 src/eric7/Utilities/ClassBrowsers/rbclbr.py --- a/src/eric7/Utilities/ClassBrowsers/rbclbr.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/Utilities/ClassBrowsers/rbclbr.py Wed Jul 13 14:55:47 2022 +0200 @@ -19,7 +19,7 @@ from . import ClbrBaseClasses SUPPORTED_TYPES = [ClassBrowsers.RB_SOURCE] - + _getnext = re.compile( r""" (?P<String> @@ -156,17 +156,19 @@ end \b [^_] ) )""", - re.VERBOSE | re.DOTALL | re.MULTILINE).search + re.VERBOSE | re.DOTALL | re.MULTILINE, +).search _commentsub = re.compile(r"""#[^\n]*\n|#[^\n]*$""").sub -_modules = {} # cache of modules we've seen +_modules = {} # cache of modules we've seen class VisibilityMixin(ClbrBaseClasses.ClbrVisibilityMixinBase): """ Mixin class implementing the notion of visibility. """ + def __init__(self): """ Constructor @@ -178,18 +180,18 @@ """ Class to represent a Ruby class. """ + def __init__(self, module, name, superClasses, file, lineno): """ Constructor - + @param module name of the module containing this class @param name name of this class @param superClasses list of class names this class is inherited from @param file filename containing this class @param lineno linenumber of the class definition """ - ClbrBaseClasses.Class.__init__(self, module, name, superClasses, file, - lineno) + ClbrBaseClasses.Class.__init__(self, module, name, superClasses, file, lineno) VisibilityMixin.__init__(self) @@ -197,10 +199,11 @@ """ Class to represent a Ruby module. """ + def __init__(self, module, name, file, lineno): """ Constructor - + @param module name of the module containing this class @param name name of this class @param file filename containing this class @@ -214,11 +217,11 @@ """ Class to represent a Ruby function. """ - def __init__(self, module, name, file, lineno, signature='', - separator=','): + + def __init__(self, module, name, file, lineno, signature="", separator=","): """ Constructor - + @param module name of the module containing this function @param name name of this function @param file filename containing this class @@ -226,8 +229,9 @@ @param signature parameterlist of the method @param separator string separating the parameters """ - ClbrBaseClasses.Function.__init__(self, module, name, file, lineno, - signature, separator) + ClbrBaseClasses.Function.__init__( + self, module, name, file, lineno, signature, separator + ) VisibilityMixin.__init__(self) @@ -235,10 +239,11 @@ """ Class to represent a class or module attribute. """ + def __init__(self, module, name, file, lineno): """ Constructor - + @param module name of the module containing this class @param name name of this class @param file filename containing this attribute @@ -258,7 +263,7 @@ @return the resulting dictionary """ global _modules - + if module in _modules: # we've seen this file before... return _modules[module] @@ -280,7 +285,7 @@ # can't do anything with this module _modules[module] = {} return {} - + _modules[module] = scan(src, file, module) return _modules[module] @@ -288,7 +293,7 @@ def scan(src, file, module): """ Public method to scan the given source text. - + @param src source text to be scanned @type str @param file file name associated with the source text @@ -305,7 +310,7 @@ dict_counts = {} classstack = [] # stack of (class, indent) pairs - acstack = [] # stack of (access control, indent) pairs + acstack = [] # stack of (access control, indent) pairs indent = 0 lineno, last_lineno_pos = 1, 0 @@ -323,18 +328,18 @@ thisindent = indent indent += 1 meth_name = ( - m.group("MethodName") or - m.group("MethodName2") or - m.group("MethodName3") + 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 '' - meth_sig = _commentsub('', meth_sig) - lineno += src.count('\n', last_lineno_pos, start) + meth_sig = meth_sig and meth_sig.replace("\\\n", "") or "" + meth_sig = _commentsub("", meth_sig) + lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start - if meth_name.startswith('self.'): + if meth_name.startswith("self."): meth_name = meth_name[5:] - elif meth_name.startswith('self::'): + 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: @@ -349,8 +354,7 @@ cur_class = classstack[-1][0] if isinstance(cur_class, (Class, Module)): # it's a method - f = Function(None, meth_name, - file, lineno, meth_sig) + f = Function(None, meth_name, file, lineno, meth_sig) cur_class._addmethod(meth_name, f) else: f = cur_class @@ -366,12 +370,10 @@ # else it's a nested def else: # it's a function - f = Function(module, meth_name, - file, lineno, meth_sig) + f = Function(module, meth_name, file, lineno, meth_sig) if meth_name in dict_counts: dict_counts[meth_name] += 1 - meth_name = "{0}_{1:d}".format( - meth_name, dict_counts[meth_name]) + meth_name = "{0}_{1:d}".format(meth_name, dict_counts[meth_name]) else: dict_counts[meth_name] = 0 dictionary[meth_name] = f @@ -385,10 +387,10 @@ classstack.append((f, thisindent)) # Marker for nested fns elif ( - m.start("String") >= 0 or - m.start("Comment") >= 0 or - m.start("ClassIgnored") >= 0 or - m.start("BeginEnd") >= 0 + m.start("String") >= 0 + or m.start("Comment") >= 0 + or m.start("ClassIgnored") >= 0 + or m.start("BeginEnd") >= 0 ): pass @@ -396,7 +398,7 @@ # we found a class definition thisindent = indent indent += 1 - 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: @@ -409,10 +411,9 @@ if inherit: # the class inherits from other classes inherit = inherit[1:].strip() - inherit = [_commentsub('', inherit)] + inherit = [_commentsub("", inherit)] # remember this class - cur_class = Class(module, class_name, inherit, - file, lineno) + cur_class = Class(module, class_name, inherit, file, lineno) if not classstack: if class_name in dictionary: cur_class = dictionary[class_name] @@ -441,7 +442,7 @@ # we found a module definition thisindent = indent indent += 1 - 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: @@ -483,8 +484,8 @@ while index >= -len(acstack): if acstack[index][1] < indent: actype = ( - m.group("AccessControlType") or - m.group("AccessControlType2").split('_')[0] + m.group("AccessControlType") + or m.group("AccessControlType2").split("_")[0] ) acstack[index][0] = actype.lower() break @@ -494,18 +495,18 @@ index = -1 while index >= -len(classstack): if ( - classstack[index][0] is not None and - not isinstance(classstack[index][0], Function) and - classstack[index][1] < indent + classstack[index][0] is not None + and not isinstance(classstack[index][0], Function) + and classstack[index][1] < indent ): parent = classstack[index][0] actype = ( - m.group("AccessControlType") or - m.group("AccessControlType2").split('_')[0] + m.group("AccessControlType") + or m.group("AccessControlType2").split("_")[0] ) actype = actype.lower() for name in aclist.split(","): - name = name.strip()[1:] # get rid of leading ':' + name = name.strip()[1:] # get rid of leading ':' acmeth = parent._getmethod(name) if acmeth is None: continue @@ -520,17 +521,16 @@ index -= 1 elif m.start("Attribute") >= 0: - 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): if ( - classstack[index][0] is not None and - not isinstance(classstack[index][0], Function) and - classstack[index][1] < indent + classstack[index][0] is not None + and not isinstance(classstack[index][0], Function) + and classstack[index][1] < indent ): - attr = Attribute( - module, m.group("AttributeName"), file, lineno) + attr = Attribute(module, m.group("AttributeName"), file, lineno) classstack[index][0]._addattribute(attr) break else: @@ -540,25 +540,25 @@ lastGlobalEntry = None elif m.start("Attr") >= 0: - 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): if ( - classstack[index][0] is not None and - not isinstance(classstack[index][0], Function) and - classstack[index][1] < indent + classstack[index][0] is not None + and not isinstance(classstack[index][0], Function) + and classstack[index][1] < indent ): parent = classstack[index][0] if m.group("AttrType") is None: nv = m.group("AttrList").split(",") if not nv: break - name = nv[0].strip()[1:] # get rid of leading ':' + name = nv[0].strip()[1:] # get rid of leading ':' attr = ( - parent._getattribute("@" + name) or - parent._getattribute("@@" + name) or - Attribute(module, "@" + name, file, lineno) + parent._getattribute("@" + name) + or parent._getattribute("@@" + name) + or Attribute(module, "@" + name, file, lineno) ) if len(nv) == 1 or nv[1].strip() == "false": attr.setProtected() @@ -568,11 +568,11 @@ else: access = m.group("AttrType") for name in m.group("AttrList").split(","): - name = name.strip()[1:] # get rid of leading ':' + name = name.strip()[1:] # get rid of leading ':' attr = ( - parent._getattribute("@" + name) or - parent._getattribute("@@" + name) or - Attribute(module, "@" + name, file, lineno) + parent._getattribute("@" + name) + or parent._getattribute("@@" + name) + or Attribute(module, "@" + name, file, lineno) ) if access == "_accessor": attr.setPublic() @@ -600,14 +600,15 @@ indent = classstack[-1][1] else: indent = 0 - + elif m.start("CodingLine") >= 0: # a coding statement coding = m.group("Coding") - lineno += src.count('\n', last_lineno_pos, start) + lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start if "@@Coding@@" not in dictionary: dictionary["@@Coding@@"] = ClbrBaseClasses.Coding( - module, file, lineno, coding) + module, file, lineno, coding + ) return dictionary