Skip to content

Commit e238b6b

Browse files
🔧 mypy- disallow 'any generics' (#865)
Co-authored-by: Chris Sewell <chrisj_sewell@hotmail.com>
1 parent 4e7128c commit e238b6b

5 files changed

Lines changed: 22 additions & 9 deletions

File tree

myst_parser/inventory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def read_compressed_lines(self) -> Iterator[str]:
231231

232232

233233
@functools.lru_cache(maxsize=256)
234-
def _create_regex(pat: str) -> re.Pattern:
234+
def _create_regex(pat: str) -> re.Pattern[str]:
235235
r"""Create a regex from a pattern, that can include `*` wildcards,
236236
to match 0 or more characters.
237237

myst_parser/mdit_to_docutils/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from docutils.parsers.rst.languages import get_language as get_language_rst
3434
from docutils.statemachine import StringList
3535
from docutils.transforms.components import Filter
36-
from docutils.utils import Reporter, new_document
36+
from docutils.utils import Reporter, SystemMessage, new_document
3737
from docutils.utils.code_analyzer import Lexer, LexerError, NumberLines
3838
from markdown_it import MarkdownIt
3939
from markdown_it.common.utils import escapeHtml
@@ -379,7 +379,7 @@ def _restore():
379379
@contextmanager
380380
def current_node_context(
381381
self, node: nodes.Element, append: bool = False
382-
) -> Iterator:
382+
) -> Iterator[None]:
383383
"""Context manager for temporarily setting the current node."""
384384
if append:
385385
self.current_node.append(node)
@@ -1724,7 +1724,7 @@ def run_directive(
17241724
self.document.current_line = position
17251725

17261726
# get directive class
1727-
output: tuple[Directive | None, list] = directives.directive(
1727+
output: tuple[Directive | None, list[SystemMessage]] = directives.directive(
17281728
name, self.language_module_rst, self.document
17291729
)
17301730
directive_class, messages = output

myst_parser/mocking.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ def parse_directive_block(
127127
content: StringList,
128128
line_offset: int,
129129
directive: type[Directive],
130-
option_presets: dict,
131-
) -> tuple[list, dict, StringList, int]:
130+
option_presets: dict[str, Any],
131+
) -> tuple[list[str], dict[str, Any], StringList, int]:
132132
"""Parse the full directive text
133133
134134
:raises MarkupError: for errors in parsing the directive
@@ -324,8 +324,8 @@ def __init__(
324324
renderer: DocutilsRenderer,
325325
name: str,
326326
klass: Include,
327-
arguments: list,
328-
options: dict,
327+
arguments: list[str],
328+
options: dict[str, Any],
329329
body: list[str],
330330
lineno: int,
331331
):

myst_parser/parsers/docutils_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def _validate_url_schemes(
124124
return output
125125

126126

127-
def _attr_to_optparse_option(at: Field, default: Any) -> Tuple[dict, str]:
127+
def _attr_to_optparse_option(at: Field, default: Any) -> Tuple[Dict[str, Any], str]:
128128
"""Convert a field into a Docutils optparse options dict.
129129
130130
:returns: (option_dict, default)

pyproject.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,24 @@ show_error_codes = true
114114
check_untyped_defs = true
115115
strict_equality = true
116116
warn_unused_ignores = true
117+
disallow_any_generics = true
117118

118119
[[tool.mypy.overrides]]
119120
module = ["docutils.*", "yaml.*", "pygments.*"]
120121
ignore_missing_imports = true
121122

123+
[[tool.mypy.overrides]]
124+
# shrink me
125+
module = [
126+
"myst_parser.config.dc_validators",
127+
"myst_parser.config.main",
128+
"myst_parser.inventory",
129+
"myst_parser.parsers.directives",
130+
"myst_parser.parsers.docutils_",
131+
"myst_parser.parsers.parse_html",
132+
]
133+
disallow_any_generics = false
134+
122135
[tool.pytest.ini_options]
123136
filterwarnings = [
124137
"ignore:.*The default for the setting.*:FutureWarning",

0 commit comments

Comments
 (0)