From c2421694431f2e25f2f5f1639a93baa36e613ce5 Mon Sep 17 00:00:00 2001 From: jh-RLI Date: Wed, 16 Aug 2023 22:47:36 +0200 Subject: [PATCH] fix all remaining flake8 errors, and add a few error codes to the ignore list (tox.ini) as they are difficualt to handle when creting example docstrings #21 --- super_repo/example_calculator.py | 16 ++++++++++------ super_repo/example_google.py | 21 +++++++++++++++++---- tests/test_example.py | 24 +++++++++++++----------- tox.ini | 6 ++++++ 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/super_repo/example_calculator.py b/super_repo/example_calculator.py index 8156a31..1580745 100644 --- a/super_repo/example_calculator.py +++ b/super_repo/example_calculator.py @@ -1,19 +1,20 @@ # -*- coding: utf-8 -*- -""" +"""Example. + Example implementation of test for the calculater functionality to demonstrate TDD. SPDX-FileCopyrightText: 2023 Jonas Huber <@jh-RLI> SPDX-FileCopyrightText: © Reiner Lemoine Institut - SPDX-License-Identifier: MIT """ def add(a, b): - """ + """Add. + Add two numbers. :param a: The first number. @@ -24,7 +25,8 @@ def add(a, b): def subtract(a, b): - """ + """Subtract. + Subtract two numbers. :param a: The first number. @@ -35,7 +37,8 @@ def subtract(a, b): def multiply(a, b): - """ + """Multiply. + Multiply two numbers. :param a: The first number. @@ -46,7 +49,8 @@ def multiply(a, b): def divide(a, b): - """ + """Divide. + Divide two numbers. :param a: The numerator. diff --git a/super_repo/example_google.py b/super_repo/example_google.py index 2b4e9a9..2c9fba1 100644 --- a/super_repo/example_google.py +++ b/super_repo/example_google.py @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- -"""Example Google style docstrings. + +""" +Example Google style docstrings. This module demonstrates documentation as specified by the `Google Python Style Guide`_. Docstrings may extend over multiple lines. Sections are created with a section header and a colon followed by a block of indented text. Example: + Examples can be given using either the ``Example`` or ``Examples`` sections. Sections support any reStructuredText formatting, including literal blocks:: @@ -16,6 +19,7 @@ are also implicitly created anytime a new section starts. Attributes: + module_level_variable1 (int): Module level variables may be documented in either the ``Attributes`` section of the module docstring, or in an inline docstring immediately following the variable. @@ -25,10 +29,12 @@ with it. Todo: + * For module TODOs * You have to also use ``sphinx.ext.todo`` extension .. _Google Python Style Guide: + http://google.github.io/styleguide/pyguide.html """ @@ -51,13 +57,16 @@ def function_with_types_in_docstring(param1, param2): included in the docstring: Args: + param1 (int): The first parameter. param2 (str): The second parameter. Returns: + bool: The return value. True for success, False otherwise. .. _PEP 484: + https://www.python.org/dev/peps/pep-0484/ """ @@ -67,10 +76,12 @@ def function_with_pep484_type_annotations(param1: int, param2: str) -> bool: """Example function with PEP 484 type annotations. Args: + param1: The first parameter. param2: The second parameter. Returns: + The return value. True for success, False otherwise. """ @@ -231,8 +242,9 @@ def readonly_property(self): @property def readwrite_property(self): - """:obj:`list` of :obj:`str`: Properties with both a getter and setter - should only be documented in their getter method. + """:obj:`list` of :obj:`str`: Properties with both a getter and setter. + + (should only be documented in their getter method) If the setter method contains notable behavior, it should be mentioned here. @@ -244,7 +256,8 @@ def readwrite_property(self, value): value def example_method(self, param1, param2): - """Class methods are similar to regular functions. + """ + Class methods are similar to regular functions. Note: Do not include the `self` parameter in the ``Args`` section. diff --git a/tests/test_example.py b/tests/test_example.py index 8963a72..5cf6120 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -1,6 +1,8 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- #noqa -""" Example implementation of common calculater functionality to +"""Exampl. + +Example implementation of common calculater functionality to demonstrate TDD. @@ -10,40 +12,40 @@ SPDX-License-Identifier: MIT """ -from super_repo.example_calculator import add, subtract, multiply, divide +from super_repo.example_calculator import add, divide, multiply, subtract def test_addition(): - """ + """Test addition. + Test addition function. """ - result = add(3, 4) assert result == 7 def test_subtraction(): - """ + """Test subtraction. + Test subtraction function. """ - result = subtract(10, 5) assert result == 5 def test_multiplication(): - """ + """Test multiplication. + Test multiplication function. """ - result = multiply(2, 6) assert result == 12 def test_division(): - """ + """Test division. + Test division function. """ - result = divide(15, 3) assert result == 5 diff --git a/tox.ini b/tox.ini index 551a4b7..b81801d 100644 --- a/tox.ini +++ b/tox.ini @@ -75,11 +75,17 @@ commands = [flake8] max_line_length = 80 hang-closing = true +; D407 # Dont know what to do +; D406 # Dont know what to do +; D401 # Not suitable for example docstring names ignore = W293 W503 D412 D105 + D407 + D406 + D401 per-file-ignores = setup.py:E501 docstring-convention = numpy # normally I exclude init because it is very hard to configure init