Skip to main content

all: add pyproject.toml config; add missing docstrings

ID
00cb88c
date
2026-05-17 15:38:00+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
99dce42
message
all: add pyproject.toml config; add missing docstrings
changed files
5 files, 47 additions, 8 deletions

Changed files

concurrently.py (1520) → concurrently.py (1605)

diff --git a/concurrently.py b/concurrently.py
index 0737644..489d409 100644
--- a/concurrently.py
+++ b/concurrently.py
@@ -1,3 +1,7 @@
+"""
+A snippet for running multiple, concurrent invocations of a Python function.
+"""
+
 from collections.abc import Callable, Iterable
 import concurrent.futures
 import itertools
@@ -12,15 +16,15 @@ def concurrently(
     handler: Callable[[In], Out], inputs: Iterable[In], *, max_concurrency: int = 5
 ) -> Iterable[tuple[In, Out]]:
     """
-    Calls the function ``handler`` on the values ``inputs``.
+    Call the function ``handler`` on the values ``inputs``.
 
     ``handler`` should be a function that takes a single input, which is the
     individual values in the iterable ``inputs``.
 
     Generates (input, output) tuples as the calls to ``handler`` complete.
 
-    See https://alexwlchan.net/2019/10/adventures-with-concurrent-futures/ for an explanation
-    of how this function works.
+    See https://alexwlchan.net/2019/10/adventures-with-concurrent-futures/
+    for an explanation of how this function works.
 
     """
     # Make sure we get a consistent iterator throughout, rather than

examples/downloading.py (832) → examples/downloading.py (818)

diff --git a/examples/downloading.py b/examples/downloading.py
index ce30d1a..354d3c8 100755
--- a/examples/downloading.py
+++ b/examples/downloading.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 """
-This example downloads a collection of images from https://http.cat/
+Download a collection of images from https://http.cat/.
 
 Rather than downloading the images one-by-one, it runs multiple instances
 of the download() function to complete the process faster.
@@ -14,7 +14,7 @@ from concurrently import concurrently
 
 def save_http_cat(status_code):
     """
-    Saves the JPEG from https://http.cat/ associated with this status code.
+    Save the JPEG from https://http.cat/ associated with this status code.
 
     Returns the path to the downloaded file.
     """

examples/sleepy_multiply.py (711) → examples/sleepy_multiply.py (743)

diff --git a/examples/sleepy_multiply.py b/examples/sleepy_multiply.py
index b2c1ec2..474a9c2 100755
--- a/examples/sleepy_multiply.py
+++ b/examples/sleepy_multiply.py
@@ -1,8 +1,6 @@
 #!/usr/bin/env python
 """
-This example does a "sleepy multiply".
-
-It multiples two numbers together, but with a delay before returning.
+Multiply two numbers together, but with a delay before returning.
 This mimics a computation that has to be fetched from a remote server.
 
 This example also shows how to handle functions that take multiple inputs.
@@ -14,6 +12,9 @@ from concurrently import concurrently
 
 
 def sleepy_multiply(x, y):
+    """
+    Multiply two numbers together, but with a random delay.
+    """
     time.sleep(x / 10)
     return x * y
 

pyproject.toml (0) → pyproject.toml (506)

diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..9dc18de
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,21 @@
+[tool.coverage.run]
+branch = true
+source = ["concurrently.py", "test_concurrently.py"]
+
+[tool.coverage.report]
+show_missing = true
+skip_covered = true
+fail_under = 100
+
+[tool.pytest.ini_options]
+filterwarnings = ["error"]
+
+[tool.ruff.lint]
+select = ["D", "E", "F"]
+ignore = [
+    "D200",  # unnecessary-multiline-docstring
+    "D203",  # incorrect-blank-line-before-class
+    "D205",  # missing-blank-line-after-summary
+    "D211",  # blank-line-before-class
+    "D212",  # multi-line-summary-first-line
+]

test_concurrently.py (648) → test_concurrently.py (920)

diff --git a/test_concurrently.py b/test_concurrently.py
index 2927d27..795f548 100644
--- a/test_concurrently.py
+++ b/test_concurrently.py
@@ -1,3 +1,7 @@
+"""
+Tests for `concurrently`.
+"""
+
 import random
 import time
 
@@ -5,11 +9,17 @@ from concurrently import concurrently
 
 
 def double(x: int) -> int:
+    """
+    Double a number, but with a random delay.
+    """
     time.sleep(random.random() / 100)
     return x * 2
 
 
 def test_handles_iterator() -> None:
+    """
+    Check the input is processed correctly when the input is an iterator.
+    """
     result = set(concurrently(handler=double, inputs=range(10)))
 
     assert result == {
@@ -27,6 +37,9 @@ def test_handles_iterator() -> None:
 
 
 def test_handles_list() -> None:
+    """
+    Check the input is processed correctly when the input is a list.
+    """
     result = set(concurrently(handler=double, inputs=[1, 3, 5, 7, 9, 11, 13]))
 
     assert result == {(1, 2), (3, 6), (5, 10), (7, 14), (9, 18), (11, 22), (13, 26)}