Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 mypy- disallow 'any generics' #865

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion myst_parser/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions myst_parser/mdit_to_docutils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions myst_parser/mocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
):
Expand Down
2 changes: 1 addition & 1 deletion myst_parser/parsers/docutils_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading