Skip to content

Commit

Permalink
refactor: Small fixes to type annotations
Browse files Browse the repository at this point in the history
Also for event type annotations - if, hypothetically, MkDocs started to support them.

PR #470: #470
  • Loading branch information
oprypin committed Aug 20, 2022
1 parent 03dd7a6 commit 9214b74
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
23 changes: 12 additions & 11 deletions src/mkdocstrings/extension.py
Expand Up @@ -127,17 +127,18 @@ def run(self, parent: Element, blocks: MutableSequence[str]) -> None:
el.extend(headings)

page = self._autorefs.current_page
for heading in headings:
anchor = heading.attrib["id"] # noqa: WPS440
self._autorefs.register_anchor(page, anchor) # noqa: WPS441

if "data-role" in heading.attrib:
self._handlers.inventory.register(
name=anchor, # noqa: WPS441
domain=handler.domain,
role=heading.attrib["data-role"],
uri=f"{page}#{anchor}", # noqa: WPS441
)
if page:
for heading in headings:
anchor = heading.attrib["id"] # noqa: WPS440
self._autorefs.register_anchor(page, anchor) # noqa: WPS441

if "data-role" in heading.attrib:
self._handlers.inventory.register(
name=anchor, # noqa: WPS441
domain=handler.domain,
role=heading.attrib["data-role"],
uri=f"{page}#{anchor}", # noqa: WPS441
)

parent.append(el)

Expand Down
2 changes: 1 addition & 1 deletion src/mkdocstrings/loggers.py
Expand Up @@ -11,7 +11,7 @@
try:
from jinja2 import pass_context
except ImportError: # TODO: remove once Jinja2 < 3.1 is dropped
from jinja2 import contextfunction as pass_context # noqa: WPS440
from jinja2 import contextfunction as pass_context # type: ignore # noqa: WPS440

try:
import mkdocstrings_handlers
Expand Down
8 changes: 6 additions & 2 deletions src/mkdocstrings/plugin.py
Expand Up @@ -111,7 +111,9 @@ def handlers(self) -> Handlers:
return self._handlers

# TODO: remove once watch feature is removed
def on_serve(self, server: LiveReloadServer, builder: Callable, **kwargs: Any): # noqa: W0613 (unused arguments)
def on_serve(
self, server: LiveReloadServer, config: Config, builder: Callable, *args: Any, **kwargs: Any
) -> None: # noqa: W0613 (unused arguments)
"""Watch directories.
Hook for the [`on_serve` event](https://www.mkdocs.org/user-guide/plugins/#on_serve).
Expand All @@ -121,7 +123,9 @@ def on_serve(self, server: LiveReloadServer, builder: Callable, **kwargs: Any):
Arguments:
server: The `livereload` server instance.
config: The MkDocs config object (unused).
builder: The function to build the site.
*args: Additional arguments passed by MkDocs.
**kwargs: Additional arguments passed by MkDocs.
"""
if self.config["watch"]:
Expand Down Expand Up @@ -216,7 +220,7 @@ def inventory_enabled(self) -> bool:
inventory_enabled = any(handler.enable_inventory for handler in self.handlers.seen_handlers)
return inventory_enabled

def on_env(self, env, config: Config, **kwargs):
def on_env(self, env, config: Config, *args, **kwargs) -> None:
"""Extra actions that need to happen after all Markdown rendering and before HTML rendering.
Hook for the [`on_env` event](https://www.mkdocs.org/user-guide/plugins/#on_env).
Expand Down

0 comments on commit 9214b74

Please sign in to comment.