From 1872139090fc67c97f5d72c437cf14cda4021fc4 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Thu, 19 Dec 2024 12:50:55 -0600 Subject: [PATCH] fix: type-based imports --- mdformat_frontmatter/plugin.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mdformat_frontmatter/plugin.py b/mdformat_frontmatter/plugin.py index 8518bb9..9152bab 100644 --- a/mdformat_frontmatter/plugin.py +++ b/mdformat_frontmatter/plugin.py @@ -1,14 +1,17 @@ import io import sys -from typing import Mapping +from typing import Mapping, TYPE_CHECKING from markdown_it import MarkdownIt -import mdformat.renderer -from mdformat.renderer import RenderContext, RenderTreeNode -from mdformat.renderer.typing import Render + from mdit_py_plugins.front_matter import front_matter_plugin import ruamel.yaml +if TYPE_CHECKING: + from mdformat.renderer import RenderContext, RenderTreeNode + from mdformat.renderer.typing import Render + + yaml = ruamel.yaml.YAML() # Make sure to always have `sequence >= offset + 2` yaml.indent(mapping=2, sequence=4, offset=2) @@ -20,7 +23,7 @@ def update_mdit(mdit: MarkdownIt) -> None: mdit.use(front_matter_plugin) -def _render_frontmatter(node: RenderTreeNode, context: RenderContext) -> str: +def _render_frontmatter(node: "RenderTreeNode", context: "RenderContext") -> str: # Safety check - parse and dump yaml to ensure it is correctly formatted dump_stream = io.StringIO() try: @@ -39,4 +42,4 @@ def _render_frontmatter(node: RenderTreeNode, context: RenderContext) -> str: # apply the render function to the block identified by the mdit plugin -RENDERERS: Mapping[str, Render] = {"front_matter": _render_frontmatter} +RENDERERS: Mapping[str, "Render"] = {"front_matter": _render_frontmatter}