From cbc77801a71d78632df749a7b70c65881c628660 Mon Sep 17 00:00:00 2001 From: x0Lazarus <113273587+x0Lazarus@users.noreply.github.com> Date: Fri, 18 Sep 2026 09:40:37 -0700 Subject: [PATCH 1/2] Run the pinned docformatter hook on Python 3.12 --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 524976fb..a573aaad 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,6 +34,7 @@ repos: rev: ab802050e6e96aaaf7f917fcbc333bb74e2e57f7 # frozen: v1.4.2 hooks: - id: docformatter + language_version: python3.12 - repo: https://github.com/PyCQA/flake8 rev: d93590f5be797aabb60e3b09f2f52dddb02f349f # frozen: 7.3.0 hooks: From 5f6771095df5ee4a796cfe6e9e0c4a8737514dac Mon Sep 17 00:00:00 2001 From: x0Lazarus <113273587+x0Lazarus@users.noreply.github.com> Date: Fri, 18 Sep 2026 16:13:06 -0700 Subject: [PATCH 2/2] Initialize InvalidPath exception arguments Reuse the InvalidPath initializer correction proposed by @meek2100 in https://github.com/hukkin/mdformat/pull/563 (head 9f35047f2f72017e901bec5244419d1757cd03d1). Only the return annotation and super().__init__(path) call are reused; no --config feature changes. Add regression coverage for positional and keyword construction, exception arguments, string rendering and pickle round trips. This resolves B042 and preserves the exception contract. --- src/mdformat/_cli.py | 3 ++- tests/test_cli.py | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/mdformat/_cli.py b/src/mdformat/_cli.py index 682b7896..150668a6 100644 --- a/src/mdformat/_cli.py +++ b/src/mdformat/_cli.py @@ -326,7 +326,8 @@ def separate_core_and_plugin_opts(opts: Mapping) -> tuple[dict, dict]: class InvalidPath(Exception): """Exception raised when a path does not exist.""" - def __init__(self, path: Path): + def __init__(self, path: Path) -> None: + super().__init__(path) self.path = path diff --git a/tests/test_cli.py b/tests/test_cli.py index 28c36223..b4b5efa8 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,11 +1,12 @@ import os +import pickle import sys from unittest.mock import patch import pytest import mdformat -from mdformat._cli import get_plugin_info_str, run, wrap_paragraphs +from mdformat._cli import InvalidPath, get_plugin_info_str, run, wrap_paragraphs from mdformat.plugins import CODEFORMATTERS, PARSER_EXTENSIONS from tests.utils import ( FORMATTED_MARKDOWN, @@ -92,6 +93,22 @@ def test_invalid_file(capsys): assert "does not exist" in captured.err +@pytest.mark.parametrize("use_keyword", [False, True]) +def test_invalid_path_exception(tmp_path, use_keyword): + path = tmp_path / "missing.md" + error = InvalidPath(path=path) if use_keyword else InvalidPath(path) + + assert error.path == path + assert error.args == (path,) + assert str(error) == str(path) + + restored = pickle.loads(pickle.dumps(error)) + assert isinstance(restored, InvalidPath) + assert restored.path == path + assert restored.args == error.args + assert str(restored) == str(error) + + @pytest.mark.skipif(os.name == "nt", reason="No os.mkfifo on windows") def test_fifo(tmp_path, capsys): fifo_path = tmp_path / "fifo1"