Skip to content

Commit

Permalink
fix all remaining flake8 errors, and add a few error codes to the ign…
Browse files Browse the repository at this point in the history
…ore list (tox.ini) as they are difficualt to handle when creting example docstrings #21
  • Loading branch information
jh-RLI committed Aug 16, 2023
1 parent 1b67b1c commit c242169
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
16 changes: 10 additions & 6 deletions super_repo/example_calculator.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -24,7 +25,8 @@ def add(a, b):


def subtract(a, b):
"""
"""Subtract.
Subtract two numbers.
:param a: The first number.
Expand All @@ -35,7 +37,8 @@ def subtract(a, b):


def multiply(a, b):
"""
"""Multiply.
Multiply two numbers.
:param a: The first number.
Expand All @@ -46,7 +49,8 @@ def multiply(a, b):


def divide(a, b):
"""
"""Divide.
Divide two numbers.
:param a: The numerator.
Expand Down
21 changes: 17 additions & 4 deletions super_repo/example_google.py
Original file line number Diff line number Diff line change
@@ -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::
Expand All @@ -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.
Expand All @@ -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
"""
Expand All @@ -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/
"""
Expand All @@ -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.
"""
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
24 changes: 13 additions & 11 deletions tests/test_example.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
6 changes: 6 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c242169

Please sign in to comment.