diff -r f6881d10e995 -r 2f70ca07f0af src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py --- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py Fri Dec 22 17:24:07 2023 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py Fri Dec 22 19:45:17 2023 +0100 @@ -268,8 +268,10 @@ """ Public method to save the modified file. - @param encoding encoding of the source file (string) - @return error message on failure (tuple of str) + @param encoding encoding of the source file + @type str + @return error message on failure + @rtype tuple of (str, [str]) """ if not self.__modified: # no need to write @@ -305,8 +307,10 @@ """ Private method to check, if the code should be fixed. - @param code to check (string) - @return flag indicating it should be fixed (boolean) + @param code to check + @type str + @return flag indicating it should be fixed + @rtype bool """ def mutualStartswith(a, b): @@ -315,7 +319,7 @@ against each other. @return flag indicating that one string starts with the other - (boolean) + @rtype bool """ return b.startswith(a) or a.startswith(b) @@ -367,6 +371,7 @@ Public method to apply all deferred fixes. @return dictionary containing the fix results + @rtype dict """ results = {} @@ -392,7 +397,8 @@ """ Private method to get the ID for a deferred fix. - @return ID for a deferred fix (integer) + @return ID for a deferred fix + @rtype int """ self.__lastID += 1 return self.__lastID @@ -404,6 +410,7 @@ @return tuple containing two lists of integer with start and end tuples of lines + @rtype tuple of ([int, int], [int, int]) """ logical_start = [] logical_end = [] @@ -438,12 +445,15 @@ Private method to get the logical line corresponding to the given position. - @param line line number of the issue (integer) - @param pos position inside line (integer) + @param line line number of the issue + @type int + @param pos position inside line + @type int @return tuple of a tuple of two integers giving the start of the logical line, another tuple of two integers giving the end of the logical line and a list of strings with the original source lines + @rtype tuple of ((int, int), (int, int), [str]) """ try: (logical_start, logical_end) = self.__findLogical() @@ -469,7 +479,8 @@ """ Private method to determine the indentation type. - @return string to be used for an indentation (string) + @return string to be used for an indentation + @rtype str """ sio = StringIO("".join(self.__source)) indentWord = " " # default in case of failure @@ -484,8 +495,10 @@ """ Private method to get the indentation string. - @param line line to determine the indentation string from (string) - @return indentation string (string) + @param line line to determine the indentation string from + @type str + @return indentation string + @rtype str """ return line.replace(line.lstrip(), "") @@ -496,7 +509,8 @@ @return tuple of a set of line numbers belonging to a multi line string and a set of line numbers belonging to a multi line - documentation string (tuple of two set of integer) + documentation string + @rtype tuple of (set of int, set of int) """ if self.__multiLineNumbers is None: source = "".join(self.__source) @@ -526,10 +540,14 @@ This is done by adding or removing from its initial indent only. - @param line line number of the issue (integer) - @param pos position inside line (integer) + @param line line number of the issue + @type int + @param pos position inside line + @type int @param logical logical line structure - @return flag indicating a change was done (boolean) + @type str + @return flag indicating a change was done + @rtype bool @exception ValueError raised to indicate a bad 'logical' parameter """ if not logical: @@ -570,10 +588,14 @@ """ Private method to correct whitespace at the given offset. - @param line line to be corrected (string) - @param offset offset within line (integer) - @param replacement replacement string (string) + @param line line to be corrected + @type str + @param offset offset within line + @type int + @param replacement replacement string + @type str @return corrected line + @rtype str """ left = line[:offset].rstrip(" \t") right = line[offset:].lstrip(" \t") @@ -2103,7 +2125,7 @@ Constructor @param sourceLines list of source lines including eol marker - (list of string) + @type list of str """ # Raw file lines. self.raw = sourceLines @@ -2126,7 +2148,8 @@ """ Public method to run the re-indenter. - @return flag indicating that a change was done (boolean) + @return flag indicating that a change was done + @rtype bool """ try: stats = self.__genStats(tokenize.generate_tokens(self.getline)) @@ -2204,8 +2227,10 @@ """ Public method to get a fixed line. - @param line number of the line to retrieve (integer) - @return fixed line (string) + @param line number of the line to retrieve + @type int + @return fixed line + @rtype str """ if line < len(self.after): return self.after[line] @@ -2216,7 +2241,8 @@ """ Public method to get a line of text for tokenize. - @return line of text (string) + @return line of text + @rtype str """ if self.index >= len(self.lines): line = "" @@ -2230,7 +2256,9 @@ Private method to generate the re-indent statistics. @param tokens tokens generator (tokenize._tokenize) + @type function @return reference to the generated statistics + @rtype dict """ find_stmt = True # next token begins a fresh stmt? level = 0 # current indent level @@ -2278,8 +2306,10 @@ """ Private method to count number of leading blanks. - @param line line to check (string) - @return number of leading blanks (integer) + @param line line to check + @type str + @return number of leading blanks + @rtype int """ i = 0 n = len(line) @@ -2311,7 +2341,7 @@ Constructor @param physical_lines list of physical lines to operate on - (list of strings) + @type list of str """ self.lines = physical_lines self.tokens = [] @@ -2330,7 +2360,9 @@ Private method to build a logical line from a list of tokens. @param tokens list of tokens as generated by tokenize.generate_tokens - @return logical line (string) + @type list of Token + @return logical line + @rtype str """ # from pycodestyle.py with minor modifications logical = [] @@ -2362,8 +2394,9 @@ to indent things to. @return list of lists, where each list represents valid indent levels - for the line in question, relative from the initial indent. However, - the first entry is the indent level which was expected. + for the line in question, relative from the initial indent. However, + the first entry is the indent level which was expected. + @rtype list of list """ # What follows is an adjusted version of # pycodestyle.py:continuation_line_indentation. All of the comments @@ -2539,14 +2572,21 @@ """ Constructor - @param curLine text to work on (string) - @param prevLine line before the text to work on (string) - @param nextLine line after the text to work on (string) - @param maxLength maximum allowed line length (integer) - @param eol eond-of-line marker (string) - @param indentWord string used for indentation (string) + @param curLine text to work on + @type str + @param prevLine line before the text to work on + @type str + @param nextLine line after the text to work on + @type str + @param maxLength maximum allowed line length + @type int + @param eol eond-of-line marker + @type str + @param indentWord string used for indentation + @type str @param isDocString flag indicating that the line belongs to - a documentation string (boolean) + a documentation string + @type bool """ self.__text = curLine self.__prevText = prevLine @@ -2561,7 +2601,8 @@ Public method to shorten the line wrapped by the class instance. @return tuple of a flag indicating successful shortening, the - shortened line and the changed next line (boolean, string, string) + shortened line and the changed next line + @rtype tuple of (bool, str, str) """ # 1. check for comment if self.__text.lstrip().startswith("#"): @@ -2722,8 +2763,9 @@ Private method to shorten a comment line. @param isLast flag indicating, that the line is the last comment line - (boolean) - @return shortened comment line (string) + @type bool + @return shortened comment line + @rtype str """ if len(self.__text) <= self.__maxLength: return self.__text @@ -2759,7 +2801,7 @@ Private method to break multi line strings. @return tuple of the shortened line and the changed next line - (string, string) + @rtype tuple of (str, str) """ indentation = self.__getIndent(self.__text) @@ -2821,10 +2863,13 @@ Private method to check, if the given string might be inside a string or comment. - @param line line to check (string) - @param index position inside line to check (integer) + @param line line to check + @type str + @param index position inside line to check + @type int @return flag indicating the possibility of being inside a string or comment + @rtype bool """ # Check against being in a string. for quote in ['"', "'"]: @@ -2844,10 +2889,13 @@ Private method to shorten a line of code at an operator. @param tokens tokens of the line as generated by tokenize - (list of token) - @param source code string to work at (string) - @param indent indentation string of the code line (string) - @return list of candidates (list of string) + @type list of Token + @param source code string to work at + @type str + @param indent indentation string of the code line + @type str + @return list of candidates + @rtype list of str """ candidates = [] @@ -2911,8 +2959,10 @@ Private method to remove multiline-related code that will cause syntax error. - @param text code line to work on (string) - @return normalized code line (string) + @param text code line to work on + @type str + @return normalized code line + @rtype str """ for quote in "'\"": dictPattern = r"^{q}[^{q}]*{q} *: *".format(q=quote) @@ -2933,8 +2983,10 @@ """ Private method to rank a candidate. - @param candidate candidate line to rank (string) - @return rank of the candidate (integer) + @param candidate candidate line to rank + @type str + @return rank of the candidate + @rtype int """ rank = 0 if candidate.strip(): @@ -2996,8 +3048,10 @@ Private method to determine the number of unmatched open/close brackets. - @param line line to work at (string) - @return number of unmatched open/close brackets (integer) + @param line line to work at + @type str + @return number of unmatched open/close brackets + @rtype int """ count = 0 for opening, closing in ["()", "[]", "{}"]: @@ -3010,8 +3064,10 @@ """ Private method to get the indentation string. - @param line line to determine the indentation string from (string) - @return indentation string (string) + @param line line to determine the indentation string from + @type str + @return indentation string + @rtype str """ # copied from CodeStyleFixer return line.replace(line.lstrip(), "") @@ -3020,8 +3076,10 @@ """ Private method to check the syntax of the given code fragment. - @param code code fragment to check (string) - @return flag indicating syntax is ok (boolean) + @param code code fragment to check + @type str + @return flag indicating syntax is ok + @rtype bool """ code = code.replace("\r\n", "\n").replace("\r", "\n") try: