diff --git a/myst_parser/inventory.py b/myst_parser/inventory.py index bdcd8bb0..a27e2e49 100644 --- a/myst_parser/inventory.py +++ b/myst_parser/inventory.py @@ -231,7 +231,7 @@ def read_compressed_lines(self) -> Iterator[str]: @functools.lru_cache(maxsize=256) -def _create_regex(pat: str) -> re.Pattern: +def _create_regex(pat: str) -> re.Pattern[str]: r"""Create a regex from a pattern, that can include `*` wildcards, to match 0 or more characters. diff --git a/myst_parser/mdit_to_docutils/base.py b/myst_parser/mdit_to_docutils/base.py index 0817f5ca..b2199b19 100644 --- a/myst_parser/mdit_to_docutils/base.py +++ b/myst_parser/mdit_to_docutils/base.py @@ -33,7 +33,7 @@ from docutils.parsers.rst.languages import get_language as get_language_rst from docutils.statemachine import StringList from docutils.transforms.components import Filter -from docutils.utils import Reporter, new_document +from docutils.utils import Reporter, SystemMessage, new_document from docutils.utils.code_analyzer import Lexer, LexerError, NumberLines from markdown_it import MarkdownIt from markdown_it.common.utils import escapeHtml @@ -379,7 +379,7 @@ def _restore(): @contextmanager def current_node_context( self, node: nodes.Element, append: bool = False - ) -> Iterator: + ) -> Iterator[None]: """Context manager for temporarily setting the current node.""" if append: self.current_node.append(node) @@ -1724,7 +1724,7 @@ def run_directive( self.document.current_line = position # get directive class - output: tuple[Directive | None, list] = directives.directive( + output: tuple[Directive | None, list[SystemMessage]] = directives.directive( name, self.language_module_rst, self.document ) directive_class, messages = output diff --git a/myst_parser/mocking.py b/myst_parser/mocking.py index 3fedbaed..e74201c7 100644 --- a/myst_parser/mocking.py +++ b/myst_parser/mocking.py @@ -127,8 +127,8 @@ def parse_directive_block( content: StringList, line_offset: int, directive: type[Directive], - option_presets: dict, - ) -> tuple[list, dict, StringList, int]: + option_presets: dict[str, Any], + ) -> tuple[list[str], dict[str, Any], StringList, int]: """Parse the full directive text :raises MarkupError: for errors in parsing the directive @@ -324,8 +324,8 @@ def __init__( renderer: DocutilsRenderer, name: str, klass: Include, - arguments: list, - options: dict, + arguments: list[str], + options: dict[str, Any], body: list[str], lineno: int, ): diff --git a/myst_parser/parsers/docutils_.py b/myst_parser/parsers/docutils_.py index 89a78b65..139e1086 100644 --- a/myst_parser/parsers/docutils_.py +++ b/myst_parser/parsers/docutils_.py @@ -124,7 +124,7 @@ def _validate_url_schemes( return output -def _attr_to_optparse_option(at: Field, default: Any) -> Tuple[dict, str]: +def _attr_to_optparse_option(at: Field, default: Any) -> Tuple[Dict[str, Any], str]: """Convert a field into a Docutils optparse options dict. :returns: (option_dict, default) diff --git a/pyproject.toml b/pyproject.toml index 836473b6..62d99db8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -114,11 +114,24 @@ show_error_codes = true check_untyped_defs = true strict_equality = true warn_unused_ignores = true +disallow_any_generics = true [[tool.mypy.overrides]] module = ["docutils.*", "yaml.*", "pygments.*"] ignore_missing_imports = true +[[tool.mypy.overrides]] +# shrink me +module = [ + "myst_parser.config.dc_validators", + "myst_parser.config.main", + "myst_parser.inventory", + "myst_parser.parsers.directives", + "myst_parser.parsers.docutils_", + "myst_parser.parsers.parse_html", +] +disallow_any_generics = false + [tool.pytest.ini_options] filterwarnings = [ "ignore:.*The default for the setting.*:FutureWarning",