22
33import pathlib
44import sys
5- from typing import Mapping , NoReturn , Optional
5+ from typing import MutableMapping , Optional , Sequence , Union
66
77import markdown_it
88import mdformat
2121 cache = lru_cache ()
2222
2323
24+ _ConfigOptions = MutableMapping [str , Union [int , str , Sequence [str ]]]
25+
26+
2427@cache
2528def _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