Skip to content

Commit 772644a

Browse files
committed
wip
1 parent 56e2818 commit 772644a

14 files changed

Lines changed: 174 additions & 126 deletions

File tree

config/ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ ignore = [
6464
"D417", # Missing argument description in the docstring
6565
"E501", # Line too long
6666
"G004", # Logging statement uses f-string
67+
"INP001", # File is part of an implicit namespace package
6768
"PLR0911", # Too many return statements
6869
"PLR0912", # Too many branches
6970
"PLR0913", # Too many arguments to function call

docs/recipes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ and add global CSS rules to your site using MkDocs `extra_css` option:
321321
```pycon
322322
>>> for word in ("Hello", "mkdocstrings!"):
323323
... print(word, end=" ")
324+
...
324325
Hello mkdocstrings!
325326
```
326327
````

docs/troubleshooting.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Example:
151151
```python
152152
def math_function(x, y):
153153
r"""
154-
Look at these formulas:
154+
Look at these formulas:
155155
156156
```math
157157
f(x) = \int_{-\infty}^\infty
@@ -170,6 +170,7 @@ So instead of:
170170
```python
171171
import enum
172172
173+
173174
class MyEnum(enum.Enum):
174175
v1 = 1 #: The first choice.
175176
v2 = 2 #: The second choice.
@@ -180,13 +181,15 @@ You can use:
180181
```python
181182
import enum
182183
184+
183185
class MyEnum(enum.Enum):
184186
"""My enum.
185-
187+
186188
Attributes:
187189
v1: The first choice.
188190
v2: The second choice.
189191
"""
192+
190193
v1 = 1
191194
v2 = 2
192195
```
@@ -196,6 +199,7 @@ Or:
196199
```python
197200
import enum
198201
202+
199203
class MyEnum(enum.Enum):
200204
v1 = 1
201205
"""The first choice."""
@@ -211,8 +215,9 @@ Use [`functools.wraps()`](https://docs.python.org/3.6/library/functools.html#fun
211215
```python
212216
from functools import wraps
213217

218+
214219
def my_decorator(function):
215-
"""The decorator docs."""
220+
"""The decorator docs."""
216221

217222
@wraps(function)
218223
def wrapped_function(*args, **kwargs):
@@ -222,6 +227,7 @@ def my_decorator(function):
222227

223228
return wrapped_function
224229

230+
225231
@my_decorator
226232
def my_function(*args, **kwargs):
227233
"""The function docs."""

src/mkdocstrings/extension.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ class AutoDocProcessor(BlockProcessor):
5656
regex = re.compile(r"^(?P<heading>#{1,6} *|)::: ?(?P<name>.+?) *$", flags=re.MULTILINE)
5757

5858
def __init__(
59-
self, parser: BlockParser, md: Markdown, config: dict, handlers: Handlers, autorefs: AutorefsPlugin
59+
self,
60+
parser: BlockParser,
61+
md: Markdown,
62+
config: dict,
63+
handlers: Handlers,
64+
autorefs: AutorefsPlugin,
6065
) -> None:
6166
"""Initialize the object.
6267
@@ -75,7 +80,7 @@ def __init__(
7580
self._autorefs = autorefs
7681
self._updated_envs: set = set()
7782

78-
def test(self, parent: Element, block: str) -> bool:
83+
def test(self, parent: Element, block: str) -> bool: # noqa: ARG002
7984
"""Match our autodoc instructions.
8085
8186
Arguments:
@@ -124,15 +129,15 @@ def run(self, parent: Element, blocks: MutableSequence[str]) -> None:
124129
page = self._autorefs.current_page
125130
if page:
126131
for heading in headings:
127-
anchor = heading.attrib["id"] # noqa: WPS440
128-
self._autorefs.register_anchor(page, anchor) # noqa: WPS441
132+
anchor = heading.attrib["id"]
133+
self._autorefs.register_anchor(page, anchor)
129134

130135
if "data-role" in heading.attrib:
131136
self._handlers.inventory.register(
132-
name=anchor, # noqa: WPS441
137+
name=anchor,
133138
domain=handler.domain,
134139
role=heading.attrib["data-role"],
135-
uri=f"{page}#{anchor}", # noqa: WPS441
140+
uri=f"{page}#{anchor}",
136141
)
137142

138143
parent.append(el)
@@ -187,22 +192,22 @@ def _process_block(
187192
try:
188193
data: CollectorItem = handler.collect(identifier, options)
189194
except CollectionError as exception:
190-
log.error(str(exception))
195+
log.error(str(exception)) # noqa: TRY400
191196
if PluginError is SystemExit: # When MkDocs 1.2 is sufficiently common, this can be dropped.
192-
log.error(f"Error reading page '{self._autorefs.current_page}':")
197+
log.error(f"Error reading page '{self._autorefs.current_page}':") # noqa: TRY400
193198
raise PluginError(f"Could not collect '{identifier}'") from exception
194199

195200
if handler_name not in self._updated_envs: # We haven't seen this handler before on this document.
196201
log.debug("Updating renderer's env")
197-
handler._update_env(self.md, self._config) # noqa: WPS437 (protected member OK)
202+
handler._update_env(self.md, self._config) # (protected member OK)
198203
self._updated_envs.add(handler_name)
199204

200205
log.debug("Rendering templates")
201206
try:
202207
rendered = handler.render(data, options)
203208
except TemplateNotFound as exc:
204209
theme_name = self._config["theme_name"]
205-
log.error(
210+
log.error( # noqa: TRY400
206211
f"Template '{exc.name}' not found for '{handler_name}' handler and theme '{theme_name}'.",
207212
)
208213
raise
@@ -211,12 +216,12 @@ def _process_block(
211216

212217
@classmethod
213218
@functools.lru_cache(maxsize=None) # Warn only once
214-
def _warn_about_options_key(cls):
219+
def _warn_about_options_key(cls) -> None:
215220
log.info("DEPRECATION: 'selection' and 'rendering' are deprecated and merged into a single 'options' YAML key")
216221

217222

218223
class _PostProcessor(Treeprocessor):
219-
def run(self, root: Element):
224+
def run(self, root: Element) -> None:
220225
carry_text = ""
221226
for el in reversed(root): # Reversed mainly for the ability to mutate during iteration.
222227
if el.tag == "div" and el.get("class") == "mkdocstrings":

0 commit comments

Comments
 (0)