--- a/Plugins/CheckerPlugins/Pep8/Pep257Checker.py Tue Sep 24 18:58:09 2013 +0200 +++ b/Plugins/CheckerPlugins/Pep8/Pep257Checker.py Wed Sep 25 19:43:40 2013 +0200 @@ -114,7 +114,7 @@ "D203", "D205", "D221", "D231", "D234", "D235", "D236", "D237", "D238", - "D242", "D243", "D244", "D245", + "D242", "D243", "D244", "D245", "D246", "D247", ] Messages = { @@ -196,8 +196,14 @@ "Pep257Checker", "class docstring is followed by a blank line"), "D244": QT_TRANSLATE_NOOP( "Pep257Checker", + "function/method docstring is preceded by a blank line"), + "D245": QT_TRANSLATE_NOOP( + "Pep257Checker", + "function/method docstring is followed by a blank line"), + "D246": QT_TRANSLATE_NOOP( + "Pep257Checker", "docstring summary is not followed by a blank line"), - "D245": QT_TRANSLATE_NOOP( + "D247": QT_TRANSLATE_NOOP( "Pep257Checker", "last paragraph of docstring is followed by a blank line"), } @@ -288,7 +294,7 @@ ], "classDocstring": [ (self.__checkClassDocstring, ("D104", "D205")), - (self.__checkEricNoBlankBeforeAndAfterClass, + (self.__checkEricNoBlankBeforeAndAfterClassOrFunction, ("D242", "D243")), ], "methodDocstring": [ @@ -300,7 +306,9 @@ (self.__checkEricReturn, ("D234",)), (self.__checkEricFunctionArguments, ("D235", "D236", "D237", "D238")), - (self.__checkNoBlankLineBefore, ("D141",)), +## (self.__checkNoBlankLineBefore, ("D141",)), + (self.__checkEricNoBlankBeforeAndAfterClassOrFunction, + ("D244", "D245")), ], "docstring": [ (self.__checkTripleDoubleQuotes, ("D111",)), @@ -309,8 +317,8 @@ (self.__checkEricOneLiner, ("D221",)), (self.__checkIndent, ("D122",)), (self.__checkEricEndsWithPeriod, ("D231",)), - (self.__checkEricBlankAfterSummary, ("D244",)), - (self.__checkEricNBlankAfterLastParagraph, ("D245",)), + (self.__checkEricBlankAfterSummary, ("D246",)), + (self.__checkEricNBlankAfterLastParagraph, ("D247",)), ], } @@ -1175,12 +1183,13 @@ summaryLines, lineNumber = self.__getSummaryLines(docstringContext) if len(docstrings) > lineNumber + len(summaryLines) - 1: if docstrings[lineNumber + len(summaryLines)].strip(): - self.__error(docstringContext.start() + lineNumber, 0, "D244") + self.__error(docstringContext.start() + lineNumber, 0, "D246") - def __checkEricNoBlankBeforeAndAfterClass(self, docstringContext, context): + def __checkEricNoBlankBeforeAndAfterClassOrFunction( + self, docstringContext, context): """ - Private method to check, that class docstrings have no blank line - around them. + Private method to check, that class and function/method docstrings + have no blank line around them. @param docstringContext docstring context (Pep257Context) @param context context of the docstring (Pep257Context) @@ -1189,6 +1198,7 @@ return contextLines = context.source() + isClassContext = contextLines[0].lstrip().startswith("class ") cti = 0 while cti < len(contextLines) and \ not contextLines[cti].strip().startswith( @@ -1210,10 +1220,16 @@ if cti == len(contextLines): return - if not contextLines[start - 1].strip(): - self.__error(docstringContext.start(), 0, "D242") - if not contextLines[end + 1].strip(): - self.__error(docstringContext.end(), 0, "D243") + if isClassContext: + if not contextLines[start - 1].strip(): + self.__error(docstringContext.start(), 0, "D242") + if not contextLines[end + 1].strip(): + self.__error(docstringContext.end(), 0, "D243") + else: + if not contextLines[start - 1].strip(): + self.__error(docstringContext.start(), 0, "D244") + if not contextLines[end + 1].strip(): + self.__error(docstringContext.end(), 0, "D245") def __checkEricNBlankAfterLastParagraph(self, docstringContext, context): """ @@ -1232,4 +1248,4 @@ return if not docstrings[-2].strip(): - self.__error(docstringContext.end(), 0, "D245") + self.__error(docstringContext.end(), 0, "D247")