--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py Thu Jun 04 17:57:20 2020 +0200 +++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py Sat Jun 06 19:42:15 2020 +0200 @@ -18,8 +18,8 @@ import re import tokenize -# CodeStyleCheckerDialog tries to import FixableCodeStyleIssues what fail under -# Python3. So ignore it. +# CodeStyleCheckerDialog tries to import FixableCodeStyleIssues which fails +# under Python3. So ignore it. try: import pycodestyle except ImportError: @@ -238,7 +238,7 @@ fp.write(txt) except (IOError, UnicodeError) as err: # Could not save the file! Skipping it. Reason: {0} - return ("FIXWRITE_ERROR", (str(err),)) + return ("FIXWRITE_ERROR", [str(err)]) return None @@ -272,22 +272,21 @@ return True - def fixIssue(self, line, pos, message): + def fixIssue(self, line, pos, code): """ Public method to fix the fixable issues. - @param line line number of issue (integer) - @param pos character position of issue (integer) - @param message message text (string) + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param code code of the issue + @type str @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, arguments list for the message + and an ID for a deferred fix + @rtype tuple of (int, str, list, int) """ - if isinstance(message, (tuple, list)): - code = message[0].strip() - else: - code = message.split(None, 1)[0].strip() - if ( line <= len(self.__source) and self.__codeMatch(code) and @@ -298,7 +297,7 @@ self.__modified = True self.fixed += 1 else: - res = (0, "", 0) + res = (0, "", [], 0) return res @@ -312,19 +311,19 @@ # step 1: do fixes operating on logical lines first for id_, code, line, pos in self.__stackLogical: - res, msg, _ = self.__fixes[code](code, line, pos, apply=True) + res, msg, args, _ = self.__fixes[code](code, line, pos, apply=True) if res == 1: self.__modified = True self.fixed += 1 - results[id_] = (res, msg) + results[id_] = (res, msg, args) # step 2: do fixes that change the number of lines for id_, code, line, pos in reversed(self.__stack): - res, msg, _ = self.__fixes[code](code, line, pos, apply=True) + res, msg, args, _ = self.__fixes[code](code, line, pos, apply=True) if res == 1: self.__modified = True self.fixed += 1 - results[id_] = (res, msg) + results[id_] = (res, msg, args) return results @@ -527,12 +526,16 @@ Codes: D111 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ line = line - 1 quotes = re.match(r"""\s*[ru]?('''|'|\")""", @@ -547,7 +550,7 @@ line += 1 # Triple single quotes converted to triple double quotes. - return (1, "FIXD111", 0) + return (1, "FIXD111", [], 0) def __fixD112(self, code, line, pos): """ @@ -555,12 +558,16 @@ Codes: D112, D113 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ line = line - 1 if code == "D112": @@ -577,7 +584,7 @@ ) self.__source[line] = newText # Introductory quotes corrected to be {0}""" - return (1, ('FIXD112', (insertChar,)), 0) + return (1, 'FIXD112', [insertChar], 0) def __fixD121(self, code, line, pos, apply=False): """ @@ -585,21 +592,25 @@ Codes: D121 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: line = line - 1 if not self.__source[line].lstrip().startswith( ('"""', 'r"""', 'u"""')): # only correctly formatted docstrings will be fixed - return (0, "", 0) + return (0, "", [], 0) docstring = ( self.__source[line].rstrip() + @@ -614,11 +625,11 @@ self.__source[line] = docstring self.__source[line + 1] = "" # Single line docstring put on one line. - return (1, "FIXD121", 0) + return (1, "FIXD121", [], 0) else: fixId = self.__getID() self.__stack.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixD131(self, code, line, pos): """ @@ -627,12 +638,16 @@ Codes: D131 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ line = line - 1 newText = "" @@ -660,9 +675,9 @@ if newText: self.__source[line] = newText # Period added to summary line. - return (1, "FIXD131", 0) + return (1, "FIXD131", [], 0) else: - return (0, "", 0) + return (0, "", [], 0) def __fixD141(self, code, line, pos, apply=False): """ @@ -671,24 +686,28 @@ Codes: D141 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: line = line - 1 self.__source[line - 1] = "" # Blank line before function/method docstring removed. - return (1, "FIXD141", 0) + return (1, "FIXD141", [], 0) else: fixId = self.__getID() self.__stack.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixD142(self, code, line, pos, apply=False): """ @@ -697,24 +716,28 @@ Codes: D142 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: line = line - 1 self.__source[line] = self.__eol + self.__source[line] # Blank line inserted before class docstring. - return (1, "FIXD142", 0) + return (1, "FIXD142", [], 0) else: fixId = self.__getID() self.__stack.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixD143(self, code, line, pos, apply=False): """ @@ -723,24 +746,28 @@ Codes: D143 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: line = line - 1 self.__source[line] += self.__eol # Blank line inserted after class docstring. - return (1, "FIXD143", 0) + return (1, "FIXD143", [], 0) else: fixId = self.__getID() self.__stack.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixD144(self, code, line, pos, apply=False): """ @@ -749,14 +776,18 @@ Codes: D144 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: line = line - 1 @@ -766,11 +797,11 @@ self.__source[line] += self.__eol # Blank line inserted after docstring summary. - return (1, "FIXD144", 0) + return (1, "FIXD144", [], 0) else: fixId = self.__getID() self.__stack.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixD145(self, code, line, pos, apply=False): """ @@ -779,24 +810,28 @@ Codes: D143 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: line = line - 1 self.__source[line] = self.__eol + self.__source[line] # Blank line inserted after last paragraph of docstring. - return (1, "FIXD145", 0) + return (1, "FIXD145", [], 0) else: fixId = self.__getID() self.__stack.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixD221(self, code, line, pos, apply=False): """ @@ -805,14 +840,18 @@ Codes: D221, D222 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: line = line - 1 @@ -842,11 +881,11 @@ else: # Trailing quotes put on separate line. msg = "FIXD222" - return (1, msg, 0) + return (1, msg, [], 0) else: fixId = self.__getID() self.__stack.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixD242(self, code, line, pos, apply=False): """ @@ -855,14 +894,18 @@ Codes: D242, D244 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: line = line - 1 @@ -873,11 +916,11 @@ else: # Blank line before function/method docstring removed. msg = "FIXD244" - return (1, msg, 0) + return (1, msg, [], 0) else: fixId = self.__getID() self.__stack.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixD243(self, code, line, pos, apply=False): """ @@ -886,14 +929,18 @@ Codes: D243, D245 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: line = line - 1 @@ -904,11 +951,11 @@ else: # Blank line after function/method docstring removed. msg = "FIXD245" - return (1, msg, 0) + return (1, msg, [], 0) else: fixId = self.__getID() self.__stack.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixD247(self, code, line, pos, apply=False): """ @@ -917,24 +964,28 @@ Codes: D247 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: line = line - 1 self.__source[line - 1] = "" # Blank line after last paragraph removed. - return (1, "FIXD247", 0) + return (1, "FIXD247", [], 0) else: fixId = self.__getID() self.__stack.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixE101(self, code, line, pos): """ @@ -942,12 +993,16 @@ Codes: E101, E111, W191 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if self.__reindenter is None: self.__reindenter = Reindenter(self.__source) @@ -961,9 +1016,9 @@ else: # Indentation adjusted to be a multiple of four. msg = "FIXE111" - return (1, msg, 0) + return (1, msg, [], 0) else: - return (0, "", 0) + return (0, "", [], 0) def __fixE121(self, code, line, pos, apply=False): """ @@ -972,14 +1027,18 @@ Codes: E121, E124 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: logical = self.__getLogical(line, pos) @@ -993,12 +1052,12 @@ elif code == "E124": # Indentation of closing bracket corrected. msg = "FIXE124" - return (1, msg, 0) - return (0, "", 0) + return (1, msg, [], 0) + return (0, "", [], 0) else: fixId = self.__getID() self.__stackLogical.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixE122(self, code, line, pos, apply=False): """ @@ -1006,14 +1065,18 @@ Codes: E122 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: logical = self.__getLogical(line, pos) @@ -1030,12 +1093,12 @@ self.__indentWord + text.lstrip() ) # Missing indentation of continuation line corrected. - return (1, "FIXE122", 0) - return (0, "", 0) + return (1, "FIXE122", [], 0) + return (0, "", [], 0) else: fixId = self.__getID() self.__stackLogical.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixE123(self, code, line, pos, apply=False): """ @@ -1043,14 +1106,18 @@ Codes: E123 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: logical = self.__getLogical(line, pos) @@ -1068,12 +1135,12 @@ changed = True if changed: # Closing bracket aligned to opening bracket. - return (1, "FIXE123", 0) - return (0, "", 0) + return (1, "FIXE123", [], 0) + return (0, "", [], 0) else: fixId = self.__getID() self.__stackLogical.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixE125(self, code, line, pos, apply=False): """ @@ -1082,14 +1149,18 @@ Codes: E125 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: logical = self.__getLogical(line, pos) @@ -1104,12 +1175,12 @@ self.__indentWord + text.lstrip() ) # Indentation level changed. - return (1, "FIXE125", 0) - return (0, "", 0) + return (1, "FIXE125", [], 0) + return (0, "", [], 0) else: fixId = self.__getID() self.__stackLogical.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixE126(self, code, line, pos, apply=False): """ @@ -1118,14 +1189,18 @@ Codes: E126, E133 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: logical = self.__getLogical(line, pos) @@ -1146,12 +1221,12 @@ changed = True if changed: # Indentation level of hanging indentation changed. - return (1, "FIXE126", 0) - return (0, "", 0) + return (1, "FIXE126", [], 0) + return (0, "", [], 0) else: fixId = self.__getID() self.__stackLogical.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixE127(self, code, line, pos, apply=False): """ @@ -1159,14 +1234,18 @@ Codes: E127, E128 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: logical = self.__getLogical(line, pos) @@ -1204,12 +1283,12 @@ changed = True if changed: # Visual indentation corrected. - return (1, "FIXE127", 0) - return (0, "", 0) + return (1, "FIXE127", [], 0) + return (0, "", [], 0) else: fixId = self.__getID() self.__stackLogical.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixE201(self, code, line, pos): """ @@ -1217,26 +1296,30 @@ Codes: E201, E202, E203, E211 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ line = line - 1 text = self.__source[line] if '"""' in text or "'''" in text or text.rstrip().endswith('\\'): - return (0, "", 0) + return (0, "", [], 0) newText = self.__fixWhitespace(text, pos, '') if newText == text: - return (0, "", 0) + return (0, "", [], 0) self.__source[line] = newText # Extraneous whitespace removed. - return (1, "FIXE201", 0) + return (1, "FIXE201", [], 0) def __fixE221(self, code, line, pos): """ @@ -1245,25 +1328,29 @@ Codes: E221, E222, E223, E224, E241, E242, E271, E272, E273, E274 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ line = line - 1 text = self.__source[line] if '"""' in text or "'''" in text or text.rstrip().endswith('\\'): - return (0, "", 0) + return (0, "", [], 0) newText = self.__fixWhitespace(text, pos, ' ') if newText == text: - return (0, "", 0) + return (0, "", [], 0) self.__source[line] = newText - return (1, "FIXE221", 0) + return (1, "FIXE221", [], 0) def __fixE225(self, code, line, pos): """ @@ -1271,18 +1358,22 @@ Codes: E225, E226, E227, E228 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ line = line - 1 text = self.__source[line] if '"""' in text or "'''" in text or text.rstrip().endswith('\\'): - return (0, "", 0) + return (0, "", [], 0) newText = text # determine length of operator @@ -1300,11 +1391,11 @@ newText = self.__fixWhitespace(newText, pos2, ' ') newText = self.__fixWhitespace(newText, pos, ' ') if newText == text: - return (0, "", 0) + return (0, "", [], 0) self.__source[line] = newText # Missing whitespaces added. - return (1, "FIXE225", 0) + return (1, "FIXE225", [], 0) def __fixE231(self, code, line, pos): """ @@ -1312,12 +1403,16 @@ Codes: E231 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ line = line - 1 pos = pos + 1 @@ -1327,7 +1422,7 @@ self.__source[line][pos:] ) # Missing whitespace added. - return (1, "FIXE231", 0) + return (1, "FIXE231", [], 0) def __fixE251(self, code, line, pos): """ @@ -1336,12 +1431,16 @@ Codes: E251 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ line = line - 1 text = self.__source[line] @@ -1362,7 +1461,7 @@ else: self.__source[line] = newText # Extraneous whitespace removed. - return (1, "FIXE251", 0) + return (1, "FIXE251", [], 0) def __fixE261(self, code, line, pos): """ @@ -1370,12 +1469,16 @@ Codes: E261, E262 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ line = line - 1 text = self.__source[line] @@ -1384,7 +1487,7 @@ newText = left + (" # " + right if right.strip() else right) self.__source[line] = newText # Whitespace around comment sign corrected. - return (1, "FIXE261", 0) + return (1, "FIXE261", [], 0) def __fixBlankLinesBefore(self, code, line, pos, apply=False): """ @@ -1393,14 +1496,18 @@ Codes: E301, E302, E303, E305, E306, E307, E308 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: if code in ["E301", "E306", "E307"]: @@ -1428,7 +1535,7 @@ self.__source.insert(line, self.__eol) delta += 1 # %n blank line(s) inserted. - return (1, ("FIXE302+", blankLinesBefore - blanks), 0) + return (1, "FIXE302+", blankLinesBefore - blanks, 0) elif delta > 0: # delete superfluous blank lines while delta > 0: @@ -1436,13 +1543,13 @@ line -= 1 delta -= 1 # %n superfluous line(s) removed. - return (1, ("FIXE302-", blanks - blankLinesBefore), 0) + return (1, "FIXE302-", blanks - blankLinesBefore, 0) else: - return (0, "", 0) + return (0, "", [], 0) else: fixId = self.__getID() self.__stack.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixE304(self, code, line, pos, apply=False): """ @@ -1451,14 +1558,18 @@ Codes: E304 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: index = line - 2 @@ -1469,11 +1580,11 @@ else: break # Superfluous blank lines after function decorator removed. - return (1, "FIXE304", 0) + return (1, "FIXE304", [], 0) else: fixId = self.__getID() self.__stack.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixE401(self, code, line, pos, apply=False): """ @@ -1481,26 +1592,30 @@ Codes: E401 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: line = line - 1 text = self.__source[line] if not text.lstrip().startswith("import"): - return (0, "", 0) + return (0, "", [], 0) # pycodestyle (1.3.1) reports false positive if there is an import # statement followed by a semicolon and some unrelated # statement with commas in it. if ';' in text: - return (0, "", 0) + return (0, "", [], 0) newText = ( text[:pos].rstrip("\t ,") + @@ -1511,11 +1626,11 @@ ) self.__source[line] = newText # Imports were put on separate lines. - return (1, "FIXE401", 0) + return (1, "FIXE401", [], 0) else: fixId = self.__getID() self.__stack.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixE501(self, code, line, pos, apply=False): """ @@ -1523,14 +1638,18 @@ Codes: E501 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: multilineStringLines, docStringLines = ( @@ -1560,13 +1679,13 @@ newNextText = "" self.__source[line + 1] = newNextText # Long lines have been shortened. - return (1, "FIXE501", 0) + return (1, "FIXE501", [], 0) else: - return (0, "", 0) + return (0, "", [], 0) else: fixId = self.__getID() self.__stack.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixE502(self, code, line, pos): """ @@ -1574,19 +1693,23 @@ Codes: E502 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ self.__source[line - 1] = ( self.__source[line - 1].rstrip("\n\r \t\\") + self.__eol ) # Redundant backslash in brackets removed. - return (1, "FIXE502", 0) + return (1, "FIXE502", [], 0) def __fixE701(self, code, line, pos, apply=False): """ @@ -1594,14 +1717,18 @@ Codes: E701 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: line = line - 1 @@ -1618,11 +1745,11 @@ ) self.__source[line] = newText # Compound statement corrected. - return (1, "FIXE701", 0) + return (1, "FIXE701", [], 0) else: fixId = self.__getID() self.__stack.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixE702(self, code, line, pos, apply=False): """ @@ -1630,14 +1757,18 @@ Codes: E702, E703 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: line = line - 1 @@ -1654,11 +1785,11 @@ second = text[pos:].lstrip("\n\r \t;") self.__source[line] = first + self.__getIndent(text) + second # Compound statement corrected. - return (1, "FIXE702", 0) + return (1, "FIXE702", [], 0) else: fixId = self.__getID() self.__stack.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixE711(self, code, line, pos): """ @@ -1666,12 +1797,16 @@ Codes: E711, E712 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ line = line - 1 text = self.__source[line] @@ -1685,18 +1820,18 @@ right = text[rightPos:].lstrip() if not right.startswith(("None", "True", "False")): - return (0, "", 0) + return (0, "", [], 0) if center.strip() == "==": center = "is" elif center.strip() == "!=": center = "is not" else: - return (0, "", 0) + return (0, "", [], 0) self.__source[line] = " ".join([left, center, right]) # Comparison to None/True/False corrected. - return (1, "FIXE711", 0) + return (1, "FIXE711", [], 0) def __fixN804(self, code, line, pos, apply=False): """ @@ -1705,14 +1840,18 @@ Codes: N804, N805 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: line = line - 1 @@ -1742,11 +1881,11 @@ newText = left + center + right self.__source[line] = newText # '{0}' argument added. - return (1, ("FIXN804", (arg,)), 0) + return (1, "FIXN804", [arg], 0) else: fixId = self.__getID() self.__stack.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixN806(self, code, line, pos, apply=False): """ @@ -1754,14 +1893,18 @@ Codes: N806 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) - @keyparam apply flag indicating, that the fix should be applied - (boolean) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int + @param apply flag indicating, that the fix should be applied + @type bool @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ if apply: line = line - 1 @@ -1804,11 +1947,11 @@ self.__source[line] = indent + right # '{0}' argument removed. - return (1, ("FIXN806", arg), 0) + return (1, "FIXN806", [arg], 0) else: fixId = self.__getID() self.__stack.append((fixId, code, line, pos)) - return (-1, "", fixId) + return (-1, "", [], fixId) def __fixW291(self, code, line, pos): """ @@ -1816,17 +1959,21 @@ Codes: W291, W293 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ self.__source[line - 1] = re.sub(r'[\t ]+(\r?)$', r"\1", self.__source[line - 1]) # Whitespace stripped from end of line. - return (1, "FIXW291", 0) + return (1, "FIXW291", [], 0) def __fixW292(self, code, line, pos): """ @@ -1834,16 +1981,20 @@ Codes: W292 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ self.__source[line - 1] += self.__eol # newline added to end of file. - return (1, "FIXW292", 0) + return (1, "FIXW292", [], 0) def __fixW391(self, code, line, pos): """ @@ -1851,12 +2002,16 @@ Codes: W391 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ index = line - 1 while index: @@ -1866,7 +2021,7 @@ else: break # Superfluous trailing blank lines removed from end of file. - return (1, "FIXW391", 0) + return (1, "FIXW391", [], 0) def __fixW603(self, code, line, pos): """ @@ -1874,16 +2029,20 @@ Codes: W603 - @param code code of the issue (string) - @param line line number of the issue (integer) - @param pos position inside line (integer) + @param code code of the issue + @type str + @param line line number of the issue + @type int + @param pos position inside line + @type int @return value indicating an applied/deferred fix (-1, 0, 1), - a message for the fix (string) and an ID for a deferred - fix (integer) + a message code for the fix, a list of arguments for the + message and an ID for a deferred fix + @rtype tuple of (int, str, list or int, int) """ self.__source[line - 1] = self.__source[line - 1].replace("<>", "!=") # '<>' replaced by '!='. - return (1, "FIXW603", 0) + return (1, "FIXW603", [], 0) class Reindenter(object):