--- a/src/eric7/Utilities/ClassBrowsers/pyclbr.py Tue Mar 26 10:55:04 2024 +0100 +++ b/src/eric7/Utilities/ClassBrowsers/pyclbr.py Wed Apr 10 17:03:56 2024 +0200 @@ -187,7 +187,7 @@ Class to represent a Python class. """ - def __init__(self, module, name, superClasses, file, lineno): + def __init__(self, module, name, superClasses, file, lineno, col_offset=0): """ Constructor @@ -197,12 +197,16 @@ @type str @param superClasses list of class names this class is inherited from @type list of str - @param file filename containing this class + @param file file name containing this class @type str - @param lineno linenumber of the class definition + @param lineno line number of the class definition @type int + @param col_offset column number of the class definition (defaults to 0) + @type int (optional) """ - ClbrBaseClasses.Class.__init__(self, module, name, superClasses, file, lineno) + ClbrBaseClasses.Class.__init__( + self, module, name, superClasses, file, lineno, col_offset=col_offset + ) VisibilityMixin.__init__(self) @@ -217,6 +221,7 @@ name, file, lineno, + col_offset=0, signature="", separator=",", modifierType=ClbrBaseClasses.Function.General, @@ -229,11 +234,13 @@ @type str @param name name of this function @type str - @param file filename containing this class + @param file file name containing this function @type str - @param lineno linenumber of the class definition + @param lineno line number of the function definition @type int - @param signature parameterlist of the method + @param col_offset column number of the function definition (defaults to 0) + @type int (optional) + @param signature parameter list of the function @type str @param separator string separating the parameters @type str @@ -248,10 +255,11 @@ name, file, lineno, - signature, - separator, - modifierType, - annotation, + col_offset=col_offset, + signature=signature, + separator=separator, + modifierType=modifierType, + annotation=annotation, ) VisibilityMixin.__init__(self) @@ -261,7 +269,7 @@ Class to represent a class attribute. """ - def __init__(self, module, name, file, lineno): + def __init__(self, module, name, file, lineno, col_offset=0): """ Constructor @@ -269,12 +277,16 @@ @type str @param name name of this class @type str - @param file filename containing this attribute + @param file file name containing this attribute @type str - @param lineno linenumber of the class definition + @param lineno line number of the attribute definition @type int + @param col_offset column number of the attribute definition (defaults to 0) + @type int (optional) """ - ClbrBaseClasses.Attribute.__init__(self, module, name, file, lineno) + ClbrBaseClasses.Attribute.__init__( + self, module, name, file, lineno, col_offset=col_offset + ) VisibilityMixin.__init__(self) @@ -528,6 +540,7 @@ meth_ret = _commentsub("", meth_ret) lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start + col_offset = m.capturedStart("MethodName") - m.capturedStart() if modifierType and modifierIndent == thisindent: if modifierType == "@staticmethod": modifier = ClbrBaseClasses.Function.Static @@ -564,7 +577,8 @@ meth_name, file, lineno, - meth_sig, + col_offset=col_offset, + signature=meth_sig, annotation=meth_ret, modifierType=modifier, ) @@ -578,7 +592,8 @@ meth_name, file, lineno, - meth_sig, + col_offset=col_offset, + signature=meth_sig, annotation=meth_ret, modifierType=modifier, ) @@ -608,6 +623,7 @@ classstack.pop() lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start + col_offset = m.capturedStart("ClassName") - m.capturedStart() class_name = m.captured("ClassName") inherit = m.captured("ClassSupers") if inherit: @@ -650,7 +666,9 @@ del deltastack[-1] deltaindentcalculated = False # remember this class - cur_class = Class(module, class_name, inherit, file, lineno) + cur_class = Class( + module, class_name, inherit, file, lineno, col_offset=col_offset + ) endlineno = calculateEndline(lineno, srcLines, thisindent) cur_class.setEndLine(endlineno) if not classstack: @@ -667,8 +685,10 @@ elif m.captured("Attribute") or m.captured("TypedAttribute"): if m.captured("Attribute"): attribute_name = m.captured("AttributeName") + col_offset = m.capturedStart("AttributeName") - m.capturedStart() else: attribute_name = m.captured("TypedAttributeName") + col_offset = m.capturedStart("TypedAttributeName") - m.capturedStart() lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start index = -1 @@ -676,7 +696,9 @@ if classstack[index][0] is not None and not isinstance( classstack[index][0], Function ): - attr = Attribute(module, attribute_name, file, lineno) + attr = Attribute( + module, attribute_name, file, lineno, col_offset=col_offset + ) classstack[index][0]._addattribute(attr) break else: @@ -692,12 +714,14 @@ if m.captured("Variable"): thisindent = _indent(m.captured("VariableIndent")) variable_name = m.captured("VariableName") + col_offset = m.capturedStart("VariableName") - m.capturedStart() else: thisindent = _indent(m.captured("TypedVariableIndent")) variable_name = m.captured("TypedVariableName") if keyword.iskeyword(variable_name): # only if the determined name is not a keyword (e.g. else, except) continue + col_offset = m.capturedStart("TypedVariableName") - m.capturedStart() lineno += src.count("\n", last_lineno_pos, start) last_lineno_pos = start if thisindent == 0 or not classstack: @@ -709,7 +733,9 @@ module, "Globals", file, lineno ) dictionary["@@Globals@@"]._addglobal( - Attribute(module, variable_name, file, lineno) + Attribute( + module, variable_name, file, lineno, col_offset=col_offset + ) ) else: index = -1 @@ -719,11 +745,23 @@ else: if isinstance(classstack[index][0], Class): classstack[index][0]._addglobal( - Attribute(module, variable_name, file, lineno) + Attribute( + module, + variable_name, + file, + lineno, + col_offset=col_offset, + ) ) elif isinstance(classstack[index][0], Function): classstack[index][0]._addattribute( - Attribute(module, variable_name, file, lineno) + Attribute( + module, + variable_name, + file, + lineno, + col_offset=col_offset, + ) ) break