diff --git a/src/markdown_exec/formatters/_exec_python.py b/src/markdown_exec/formatters/_exec_python.py index 4bd7813..5c58fe4 100644 --- a/src/markdown_exec/formatters/_exec_python.py +++ b/src/markdown_exec/formatters/_exec_python.py @@ -1,8 +1,8 @@ """Special module without future annotations for executing Python code.""" -from typing import Any, Dict, Optional +from typing import Any, Optional -def exec_python(code: str, filename: str, exec_globals: Optional[Dict[str, Any]] = None) -> None: +def exec_python(code: str, filename: str, exec_globals: Optional[dict[str, Any]] = None) -> None: compiled = compile(code, filename=filename, mode="exec") exec(compiled, exec_globals) # noqa: S102 diff --git a/src/markdown_exec/formatters/base.py b/src/markdown_exec/formatters/base.py index 43750e3..10fbc41 100644 --- a/src/markdown_exec/formatters/base.py +++ b/src/markdown_exec/formatters/base.py @@ -5,7 +5,7 @@ import os from contextlib import contextmanager from textwrap import indent -from typing import TYPE_CHECKING, Any, Callable, Iterator +from typing import TYPE_CHECKING, Any, Callable from uuid import uuid4 from markupsafe import Markup @@ -14,6 +14,8 @@ from markdown_exec.rendering import MarkdownConverter, add_source, code_block if TYPE_CHECKING: + from collections.abc import Iterator + from markdown.core import Markdown logger = get_logger(__name__) diff --git a/src/markdown_exec/formatters/python.py b/src/markdown_exec/formatters/python.py index bce0450..b3af2f9 100644 --- a/src/markdown_exec/formatters/python.py +++ b/src/markdown_exec/formatters/python.py @@ -50,7 +50,7 @@ def _run_python( id: str | None = None, # noqa: A002 **extra: str, ) -> str: - title = extra.get("title", None) + title = extra.get("title") code_block_id = _code_block_id(id, session, title) _code_blocks[code_block_id] = code.split("\n") exec_globals = _sessions_globals[session] if session else {} diff --git a/src/markdown_exec/mkdocs_plugin.py b/src/markdown_exec/mkdocs_plugin.py index ffa0700..1919966 100644 --- a/src/markdown_exec/mkdocs_plugin.py +++ b/src/markdown_exec/mkdocs_plugin.py @@ -5,7 +5,7 @@ import logging import os from pathlib import Path -from typing import TYPE_CHECKING, Any, MutableMapping +from typing import TYPE_CHECKING, Any from mkdocs.config import config_options from mkdocs.config.base import Config @@ -18,6 +18,8 @@ from markdown_exec.rendering import MarkdownConverter, markdown_config if TYPE_CHECKING: + from collections.abc import MutableMapping + from jinja2 import Environment from mkdocs.config.defaults import MkDocsConfig from mkdocs.structure.files import Files diff --git a/src/markdown_exec/rendering.py b/src/markdown_exec/rendering.py index aa1bd0f..385245d 100644 --- a/src/markdown_exec/rendering.py +++ b/src/markdown_exec/rendering.py @@ -3,9 +3,9 @@ from __future__ import annotations from contextlib import contextmanager -from functools import lru_cache +from functools import cache from textwrap import indent -from typing import TYPE_CHECKING, Any, Iterator +from typing import TYPE_CHECKING, Any from markdown import Markdown from markupsafe import Markup @@ -18,6 +18,7 @@ ) if TYPE_CHECKING: + from collections.abc import Iterator from xml.etree.ElementTree import Element from markdown import Extension @@ -180,7 +181,7 @@ def reset(self) -> None: # XML entities that get stashed in headings. -@lru_cache(maxsize=None) +@cache def _register_headings_processors(md: Markdown) -> None: md.treeprocessors.register( InsertHeadings(md), diff --git a/tests/conftest.py b/tests/conftest.py index e6b1857..c79722c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,7 +6,7 @@ from markdown_exec import formatter, formatters, validator -@pytest.fixture() +@pytest.fixture def md() -> Markdown: """Return a Markdown instance.