Skip to content

Commit c8aacd7

Browse files
committed
style: Format
1 parent 4ffb6c9 commit c8aacd7

File tree

8 files changed

+39
-35
lines changed

8 files changed

+39
-35
lines changed

scripts/gen_credits.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from jinja2 import StrictUndefined
1515
from jinja2.sandbox import SandboxedEnvironment
1616

17-
1817
# TODO: Remove once support for Python 3.10 is dropped.
1918
if sys.version_info >= (3, 11):
2019
import tomllib

src/mkdocstrings_handlers/python/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
from mkdocstrings_handlers.python.handler import get_handler
44

5-
__all__ = ["get_handler"] # noqa: WPS410
5+
__all__ = ["get_handler"]

src/mkdocstrings_handlers/python/handler.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,9 @@
1111
import sys
1212
import traceback
1313
from collections import ChainMap
14-
from subprocess import PIPE, Popen # noqa: S404
15-
from typing import Any, BinaryIO, Iterator, List, Optional, Sequence, Tuple
14+
from subprocess import PIPE, Popen
15+
from typing import TYPE_CHECKING, Any, BinaryIO, Iterator
1616

17-
from markdown import Markdown
18-
19-
from mkdocstrings.extension import PluginError
20-
from mkdocstrings.handlers.base import BaseHandler, CollectionError, CollectorItem
21-
from mkdocstrings.inventory import Inventory
22-
from mkdocstrings.loggers import get_logger
2317
from mkdocstrings_handlers.python.rendering import (
2418
do_brief_xref,
2519
rebuild_category_lists,
@@ -28,6 +22,14 @@
2822
sort_object,
2923
)
3024

25+
from mkdocstrings.extension import PluginError
26+
from mkdocstrings.handlers.base import BaseHandler, CollectionError, CollectorItem
27+
from mkdocstrings.inventory import Inventory
28+
from mkdocstrings.loggers import get_logger
29+
30+
if TYPE_CHECKING:
31+
from markdown import Markdown
32+
3133
# TODO: add a deprecation warning once the new handler handles 95% of use-cases
3234

3335
logger = get_logger(__name__)
@@ -116,12 +118,12 @@ class PythonHandler(BaseHandler):
116118
117119
- `show_bases` (`bool`): Show the base classes of a class. Default: `True`.
118120
- `show_source` (`bool`): Show the source code of this object. Default: `True`.
119-
""" # noqa: E501
121+
"""
120122

121-
def __init__( # noqa: WPS231
123+
def __init__(
122124
self,
123125
*args,
124-
setup_commands: Optional[List[str]] = None,
126+
setup_commands: list[str] | None = None,
125127
config_file_path: str | None = None,
126128
paths: list[str] | None = None,
127129
**kwargs,
@@ -150,17 +152,16 @@ def __init__( # noqa: WPS231
150152
paths.append(os.path.dirname(config_file_path))
151153
search_paths = []
152154
for path in paths:
153-
if not os.path.isabs(path):
154-
if config_file_path:
155-
path = os.path.abspath(os.path.join(os.path.dirname(config_file_path), path))
155+
if not os.path.isabs(path) and config_file_path:
156+
path = os.path.abspath(os.path.join(os.path.dirname(config_file_path), path))
156157
if path not in search_paths:
157158
search_paths.append(path)
158159
self._paths = search_paths
159160

160161
commands = []
161162

162163
if search_paths:
163-
commands.extend([f"sys.path.insert(0, {path!r})" for path in reversed(search_paths)]) # noqa: WPS441
164+
commands.extend([f"sys.path.insert(0, {path!r})" for path in reversed(search_paths)])
164165

165166
if setup_commands:
166167
# prevent the Python interpreter or the setup commands
@@ -172,7 +173,7 @@ def __init__( # noqa: WPS231
172173
*setup_commands,
173174
"sys.stdout.flush()",
174175
"sys.stdout = sys.__stdout__", # restore stdout
175-
]
176+
],
176177
)
177178

178179
if commands:
@@ -186,7 +187,7 @@ def __init__( # noqa: WPS231
186187
else:
187188
cmd = [sys.executable, "-m", "pytkdocs", "--line-by-line"]
188189

189-
self.process = Popen( # noqa: S603,S607 (we trust the input, and we don't want to use the absolute path)
190+
self.process = Popen(
190191
cmd,
191192
universal_newlines=True,
192193
stdout=PIPE,
@@ -198,8 +199,12 @@ def __init__( # noqa: WPS231
198199

199200
@classmethod
200201
def load_inventory(
201-
cls, in_file: BinaryIO, url: str, base_url: Optional[str] = None, **kwargs
202-
) -> Iterator[Tuple[str, str]]:
202+
cls,
203+
in_file: BinaryIO,
204+
url: str,
205+
base_url: str | None = None,
206+
**kwargs,
207+
) -> Iterator[tuple[str, str]]:
203208
"""Yield items and their URLs from an inventory file streamed from `in_file`.
204209
205210
This implements mkdocstrings' `load_inventory` "protocol" (see plugin.py).
@@ -216,10 +221,10 @@ def load_inventory(
216221
if base_url is None:
217222
base_url = posixpath.dirname(url)
218223

219-
for item in Inventory.parse_sphinx(in_file, domain_filter=("py",)).values(): # noqa: WPS526
224+
for item in Inventory.parse_sphinx(in_file, domain_filter=("py",)).values():
220225
yield item.name, posixpath.join(base_url, item.uri)
221226

222-
def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: WPS231
227+
def collect(self, identifier: str, config: dict) -> CollectorItem:
223228
"""Collect the documentation tree given an identifier and selection options.
224229
225230
In this method, we feed one line of JSON to the standard input of the subprocess that was opened
@@ -338,9 +343,9 @@ def update_env(self, md: Markdown, config: dict) -> None: # noqa: D102 (ignore
338343

339344

340345
def get_handler(
341-
theme: str, # noqa: W0613 (unused argument config)
342-
custom_templates: Optional[str] = None,
343-
setup_commands: Optional[List[str]] = None,
346+
theme: str,
347+
custom_templates: str | None = None,
348+
setup_commands: list[str] | None = None,
344349
config_file_path: str | None = None,
345350
paths: list[str] | None = None,
346351
**config: Any,

src/mkdocstrings_handlers/python/rendering.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
from __future__ import annotations
44

55
import sys
6-
from typing import Any, Callable
6+
from typing import TYPE_CHECKING, Any, Callable
77

88
from markupsafe import Markup
99

10-
from mkdocstrings.handlers.base import CollectorItem
1110
from mkdocstrings.loggers import get_logger
1211

12+
if TYPE_CHECKING:
13+
from mkdocstrings.handlers.base import CollectorItem
14+
1315
log = get_logger(__name__)
1416

1517

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def fixture_mkdocs_conf(request, tmp_path):
1919
MkDocs configuration object.
2020
"""
2121
conf = MkDocsConfig()
22-
while hasattr(request, "_parent_request") and hasattr(request._parent_request, "_parent_request"): # noqa: WPS437
23-
request = request._parent_request # noqa: WPS437
22+
while hasattr(request, "_parent_request") and hasattr(request._parent_request, "_parent_request"):
23+
request = request._parent_request
2424

2525
conf_dict = {
2626
"site_name": "foo",

tests/test_collector.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
# -*- coding: utf-8 -*-
21
"""Tests for the `collector` module."""
32
from unittest import mock
43

54
import pytest
5+
from mkdocstrings_handlers.python import get_handler
66

77
from mkdocstrings.handlers.base import CollectionError
8-
from mkdocstrings_handlers.python import get_handler
98

109

1110
@pytest.mark.parametrize(

tests/test_renderer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from copy import deepcopy
44

5-
from mkdocstrings_handlers.python.rendering import ( # noqa: WPS450
5+
from mkdocstrings_handlers.python.rendering import (
66
rebuild_category_lists,
77
sort_key_alphabetical,
88
sort_key_source,

tests/test_themes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Tests for the different themes we claim to support."""
22

3-
import sys
43

54
import pytest
65

@@ -34,6 +33,6 @@ def test_render_themes_templates(module, plugin):
3433
plugin: The plugin instance (parametrized fixture).
3534
"""
3635
handler = plugin.handlers.get_handler("python")
37-
handler._update_env(plugin.md, plugin.handlers._config) # noqa: WPS437
36+
handler._update_env(plugin.md, plugin.handlers._config)
3837
data = handler.collect(module, {})
3938
handler.render(data, {})

0 commit comments

Comments
 (0)