Пример #1
0
def test_docstring_return(method):
    if function_has_return(method):
        if "Returns:" not in method.__doc__:
            raise DocStringError(f"Missing returns in `{method}` docstring")
        if "return" not in inspect.getfullargspec(method).annotations:
            raise DocStringError(
                f"Type annotation missing for the `return` type in {method} docstring"
            )
Пример #2
0
def test_docstring_parameters(method):
    funct_with_ignored_args = "cls", "self"
    argspec = inspect.getfullargspec(method)
    args = [a for a in argspec.args if a not in funct_with_ignored_args]
    if args and "Arguments:" not in method.__doc__:
        raise DocStringError(
            f"`Arguments` block missing in `{method}` docstring")
    for arg in args:
        if arg in funct_with_ignored_args:
            continue
        if arg not in method.__doc__:
            raise DocStringError(f"{arg} not described in {method} docstring")
        if arg not in argspec.annotations:
            raise DocStringError(f"{arg} not type annotated in {method}")
Пример #3
0
def test_docstring_has_example(method):
    if "```python" not in method.__doc__:
        raise DocStringError(f"Missing example in `{method}` docstring")
Пример #4
0
def test_has_docstring(method):
    if not method.__doc__:
        raise DocStringError(f"Missing docstring in `{method}`")