|
1 | 1 | import argparse |
2 | | -from collections import OrderedDict |
3 | 2 | import configparser |
4 | 3 | import glob as fileglob |
5 | 4 | from io import StringIO |
6 | 5 | import os |
7 | 6 | import re |
8 | 7 | import sys |
9 | 8 |
|
10 | | -import toml |
| 9 | +import tomli |
11 | 10 | from typing import (Any, Callable, Dict, List, Mapping, MutableMapping, Optional, Sequence, |
12 | | - TextIO, Tuple, Union, cast) |
| 11 | + TextIO, Tuple, Union) |
13 | 12 | from typing_extensions import Final |
14 | 13 |
|
15 | 14 | from mypy import defaults |
@@ -169,20 +168,20 @@ def parse_config_file(options: Options, set_strict_flags: Callable[[], None], |
169 | 168 | continue |
170 | 169 | try: |
171 | 170 | if is_toml(config_file): |
172 | | - toml_data = cast("OrderedDict[str, Any]", |
173 | | - toml.load(config_file, _dict=OrderedDict)) |
| 171 | + with open(config_file, encoding="utf-8") as f: |
| 172 | + toml_data = tomli.load(f) |
174 | 173 | # Filter down to just mypy relevant toml keys |
175 | 174 | toml_data = toml_data.get('tool', {}) |
176 | 175 | if 'mypy' not in toml_data: |
177 | 176 | continue |
178 | | - toml_data = OrderedDict({'mypy': toml_data['mypy']}) |
| 177 | + toml_data = {'mypy': toml_data['mypy']} |
179 | 178 | parser: MutableMapping[str, Any] = destructure_overrides(toml_data) |
180 | 179 | config_types = toml_config_types |
181 | 180 | else: |
182 | 181 | config_parser.read(config_file) |
183 | 182 | parser = config_parser |
184 | 183 | config_types = ini_config_types |
185 | | - except (toml.TomlDecodeError, configparser.Error, ConfigTOMLValueError) as err: |
| 184 | + except (tomli.TOMLDecodeError, configparser.Error, ConfigTOMLValueError) as err: |
186 | 185 | print("%s: %s" % (config_file, err), file=stderr) |
187 | 186 | else: |
188 | 187 | if config_file in defaults.SHARED_CONFIG_FILES and 'mypy' not in parser: |
@@ -252,7 +251,7 @@ def is_toml(filename: str) -> bool: |
252 | 251 | return filename.lower().endswith('.toml') |
253 | 252 |
|
254 | 253 |
|
255 | | -def destructure_overrides(toml_data: "OrderedDict[str, Any]") -> "OrderedDict[str, Any]": |
| 254 | +def destructure_overrides(toml_data: Dict[str, Any]) -> Dict[str, Any]: |
256 | 255 | """Take the new [[tool.mypy.overrides]] section array in the pyproject.toml file, |
257 | 256 | and convert it back to a flatter structure that the existing config_parser can handle. |
258 | 257 |
|
|
0 commit comments