diff -r 2971d5d19951 -r e8eb8370ea94 eric6/Plugins/CheckerPlugins/CodeStyleChecker/DocStyle/DocStyleChecker.py --- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/DocStyle/DocStyleChecker.py Fri Jan 15 19:49:36 2021 +0100 +++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/DocStyle/DocStyleChecker.py Sat Jan 16 16:32:01 2021 +0100 @@ -130,7 +130,8 @@ "D203", "D205", "D206", "D221", "D222", - "D231", "D232", "D234", "D235", "D236", "D237", "D238", "D239", + "D231", "D232", "D234r", "D234y", "D235r", "D235y", "D236", "D237", + "D238", "D239", "D242", "D243", "D244", "D245", "D246", "D247", "D250", "D251", "D252", "D253", "D260", "D261", "D262", "D263", @@ -232,7 +233,8 @@ (self.__checkFunctionDocstring, ("D102", "D203")), (self.__checkImperativeMood, ("D132",)), (self.__checkNoSignature, ("D133",)), - (self.__checkEricReturn, ("D234", "D235")), + (self.__checkEricReturn, ("D234r", "D235r")), + (self.__checkEricYield, ("D234y", "D235y")), (self.__checkEricFunctionArguments, ("D236", "D237", "D238", "D239")), (self.__checkEricNoBlankBeforeAndAfterClassOrFunction, @@ -1069,17 +1071,43 @@ tokens = list( tokenize.generate_tokens(StringIO(context.ssource()).readline)) return_ = [tokens[i + 1][0] for i, token in enumerate(tokens) - if token[1] in ("return", "yield")] + if token[1] == "return"] if "@return" not in docstringContext.ssource(): if (set(return_) - {tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE} != set()): - self.__error(docstringContext.end(), 0, "D234") + self.__error(docstringContext.end(), 0, "D234r") else: if (set(return_) - {tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE} == set()): - self.__error(docstringContext.end(), 0, "D235") + self.__error(docstringContext.end(), 0, "D235r") + + def __checkEricYield(self, docstringContext, context): + """ + Private method to check, that docstrings contain an @yield line + if they return anything and don't otherwise. + + @param docstringContext docstring context (DocStyleContext) + @param context context of the docstring (DocStyleContext) + """ + if docstringContext is None: + return + + tokens = list( + tokenize.generate_tokens(StringIO(context.ssource()).readline)) + yield_ = [tokens[i + 1][0] for i, token in enumerate(tokens) + if token[1] == "yield"] + if "@yield" not in docstringContext.ssource(): + if (set(yield_) - + {tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE} != + set()): + self.__error(docstringContext.end(), 0, "D234y") + else: + if (set(yield_) - + {tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE} == + set()): + self.__error(docstringContext.end(), 0, "D235y") def __checkEricFunctionArguments(self, docstringContext, context): """