Skip to content

Commit 91bf7ee

Browse files
authored
Merge pull request #8 from jorenham/improved-typing
typing fixes
2 parents 35889f7 + acb46d8 commit 91bf7ee

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

mdformat_pyproject/plugin.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pathlib
44
import sys
5-
from typing import Mapping, NoReturn, Optional
5+
from typing import MutableMapping, Optional, Sequence, Union
66

77
import markdown_it
88
import mdformat
@@ -21,6 +21,9 @@
2121
cache = lru_cache()
2222

2323

24+
_ConfigOptions = MutableMapping[str, Union[int, str, Sequence[str]]]
25+
26+
2427
@cache
2528
def _find_pyproject_toml_path(search_path: str) -> Optional[pathlib.Path]:
2629
"""Find the pyproject.toml file that corresponds to the search path.
@@ -45,7 +48,7 @@ def _find_pyproject_toml_path(search_path: str) -> Optional[pathlib.Path]:
4548

4649

4750
@cache
48-
def _parse_pyproject(pyproject_path: pathlib.Path) -> Optional[Mapping]:
51+
def _parse_pyproject(pyproject_path: pathlib.Path) -> Optional[_ConfigOptions]:
4952
"""Extract and validate the mdformat options from the pyproject.toml file.
5053
5154
The options are searched inside a [tool.mdformat] key within the toml file,
@@ -56,11 +59,12 @@ def _parse_pyproject(pyproject_path: pathlib.Path) -> Optional[Mapping]:
5659
if options is not None:
5760
mdformat._conf._validate_keys(options, pyproject_path)
5861
mdformat._conf._validate_values(options, pyproject_path)
59-
return options
62+
63+
return options
6064

6165

6266
@cache
63-
def _reload_cli_opts() -> Mapping:
67+
def _reload_cli_opts() -> _ConfigOptions:
6468
"""Re-parse the sys.argv array to deduce which arguments were used in the CLI.
6569
6670
If unknown arguments are found, we deduce that mdformat is being used as a
@@ -93,17 +97,17 @@ def _reload_cli_opts() -> Mapping:
9397
return {key: value for key, value in vars(args).items() if value is not None}
9498

9599

96-
def update_mdit(mdit: markdown_it.MarkdownIt) -> NoReturn:
100+
def update_mdit(mdit: markdown_it.MarkdownIt) -> None:
97101
"""Read the pyproject.toml file and re-create the mdformat options."""
98-
mdformat_options = mdit.options["mdformat"]
102+
mdformat_options: _ConfigOptions = mdit.options["mdformat"]
99103
file_path = mdformat_options.get("filename", "-")
100104
pyproject_path = _find_pyproject_toml_path(file_path)
101105
if pyproject_path:
102106
pyproject_opts = _parse_pyproject(pyproject_path)
103107
if pyproject_opts is not None:
104108
cli_opts = _reload_cli_opts()
105-
new_options: Mapping = {**pyproject_opts, **cli_opts}
106-
mdformat_options.update(new_options)
109+
mdformat_options.update(**pyproject_opts)
110+
mdformat_options.update(**cli_opts)
107111

108112

109-
RENDERERS: Mapping[str, Render] = {}
113+
RENDERERS: MutableMapping[str, Render] = {}

0 commit comments

Comments
 (0)