Skip to content

Commit b2dfab8

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent b5e20f9 commit b2dfab8

8 files changed

Lines changed: 30 additions & 24 deletions

File tree

‎sphinx_external_toc/_compat.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
import dataclasses as dc
66
import re
7+
from re import Pattern
78
import sys
8-
from typing import Any, Callable, Pattern, Type
9+
from typing import Any, Callable, Type
910

1011
from docutils.nodes import Element
1112

@@ -93,7 +94,7 @@ def matches_re(regex: str | Pattern, flags: int = 0) -> ValidatorType:
9394
if fullmatch:
9495
match_func = pattern.fullmatch
9596
else: # Python 2 fullmatch emulation (https://bugs.python.org/issue16203)
96-
pattern = re.compile(r"(?:{})\Z".format(pattern.pattern), pattern.flags)
97+
pattern = re.compile(rf"(?:{pattern.pattern})\Z", pattern.flags)
9798
match_func = pattern.match
9899

99100
def _validator(inst, attr, value):

‎sphinx_external_toc/api.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Defines the `SiteMap` object, for storing the parsed ToC."""
22

3-
from collections.abc import MutableMapping
3+
from collections.abc import Iterator, MutableMapping
44
from dataclasses import asdict, dataclass
5-
from typing import Any, Dict, Iterator, List, Optional, Set, Union
5+
from typing import Any, Dict, List, Optional, Set, Union
66

77
from ._compat import (
88
DC_SLOTS,

‎sphinx_external_toc/collectors.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import gc
21
import copy
2+
import gc
3+
34
from docutils import nodes
45
from sphinx import addnodes as sphinxnodes
56
from sphinx.environment.collectors.toctree import TocTreeCollector

‎sphinx_external_toc/parsing.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""Parse the ToC to a `SiteMap` object."""
22

3-
from collections.abc import Mapping
3+
from collections.abc import Mapping, Sequence
44
from dataclasses import dataclass, fields
55
from pathlib import Path
6-
from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, Union
6+
from typing import Any, Dict, List, Optional, Set, Tuple, Union
77

88
import yaml
99

‎sphinx_external_toc/tools.py‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import re
2-
import shutil
1+
from collections.abc import Mapping, Sequence
32
from fnmatch import fnmatch
43
from itertools import chain
54
from pathlib import Path, PurePosixPath
6-
from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple, Union
5+
import re
6+
import shutil
7+
from typing import Any, Dict, List, Optional, Tuple, Union
78

89
import yaml
910

@@ -61,11 +62,11 @@ def create_site_from_toc(
6162
for docname in chain(site_map, additional_files):
6263
# create document
6364
filename = docname
64-
if not any(docname.endswith(ext) for ext in {".rst", ".md"}):
65+
if not any(docname.endswith(ext) for ext in (".rst", ".md")):
6566
filename += default_ext
6667
docpath = root_path.joinpath(PurePosixPath(filename))
6768
if docpath.exists() and not overwrite:
68-
raise IOError(f"Path already exists: {docpath}")
69+
raise OSError(f"Path already exists: {docpath}")
6970
docpath.parent.mkdir(parents=True, exist_ok=True)
7071

7172
content = []
@@ -116,7 +117,7 @@ def create_site_map_from_path(
116117
root_path, suffixes, default_index, ignore_matches
117118
)
118119
if not root_index:
119-
raise IOError(f"path does not contain a root file: {root_path}")
120+
raise OSError(f"path does not contain a root file: {root_path}")
120121

121122
# create root item and child folders
122123
root_item, indexed_folders = _doc_item_from_path(
@@ -232,7 +233,7 @@ def _assess_folder(
232233
:returns: (index file name, other file names, folders)
233234
"""
234235
if not folder.is_dir():
235-
raise IOError(f"path must be a directory: {folder}")
236+
raise OSError(f"path must be a directory: {folder}")
236237

237238
def _strip_suffix(name: str) -> str:
238239
for suffix in suffixes:

‎tests/test_cli.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from pathlib import Path
33
from typing import List
44

5-
import pytest
65
from click.testing import CliRunner
6+
import pytest
77

88
from sphinx_external_toc import __version__
99
from sphinx_external_toc.cli import (

‎tests/test_collectors.py‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import pytest
21
from unittest.mock import Mock, patch
2+
3+
import pytest
4+
from sphinx.environment.collectors.toctree import TocTreeCollector
5+
36
from sphinx_external_toc.collectors import (
47
TocTreeCollectorWithStyles,
58
disable_builtin_toctree_collector,
69
)
7-
from sphinx.environment.collectors.toctree import TocTreeCollector
810

911

1012
class TestDisableBuiltinToctreeCollector:
@@ -343,9 +345,9 @@ def test_to_roman_comprehensive(self, collector):
343345
]
344346
for num, expected in test_cases:
345347
result = collector._TocTreeCollectorWithStyles__to_roman(num)
346-
assert (
347-
result == expected
348-
), f"Failed for {num}: got {result}, expected {expected}"
348+
assert result == expected, (
349+
f"Failed for {num}: got {result}, expected {expected}"
350+
)
349351

350352
def test_to_alpha_comprehensive(self, collector):
351353
"""Test alphabetical conversion comprehensively."""
@@ -364,9 +366,9 @@ def test_to_alpha_comprehensive(self, collector):
364366
]
365367
for num, expected in test_cases:
366368
result = collector._TocTreeCollectorWithStyles__to_alpha(num)
367-
assert (
368-
result == expected
369-
), f"Failed for {num}: got {result}, expected {expected}"
369+
assert result == expected, (
370+
f"Failed for {num}: got {result}, expected {expected}"
371+
)
370372

371373
def test_disable_builtin_multiple_collectors(self):
372374
"""Test disabling with multiple collectors in memory."""

‎tests/test_compat.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for sphinx_external_toc._compat module."""
22

33
import pytest
4+
45
from sphinx_external_toc import _compat
56

67

@@ -248,8 +249,8 @@ def test_compat_module_dict(self):
248249

249250
def test_compat_import_error_handling(self):
250251
"""Test that import errors are handled gracefully."""
251-
import sys
252252
import importlib
253+
import sys
253254

254255
if "sphinx_external_toc._compat" in sys.modules:
255256
del sys.modules["sphinx_external_toc._compat"]

0 commit comments

Comments
 (0)