From 524b60e07156fbfb5ba666af47c1f22aac54c660 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Date: Wed, 1 Dec 2021 20:04:13 +0100 Subject: [PATCH] Disable universal newlines when reading TOML (#10893) * Disable universal newlines when reading TOML * Update mypy/modulefinder.py Co-authored-by: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> * Update mypy/config_parser.py Co-authored-by: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Co-authored-by: Ivan Levkivskyi --- mypy-requirements.txt | 2 +- mypy/config_parser.py | 2 +- mypy/modulefinder.py | 4 ++-- setup.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mypy-requirements.txt b/mypy-requirements.txt index 62a3afeb6a8c..a6a8afc60eeb 100644 --- a/mypy-requirements.txt +++ b/mypy-requirements.txt @@ -1,4 +1,4 @@ typing_extensions>=3.7.4 mypy_extensions>=0.4.3,<0.5.0 typed_ast>=1.4.0,<2 -tomli>=1.1.0,<1.2.0 +tomli>=1.1.0,<2.0.0 diff --git a/mypy/config_parser.py b/mypy/config_parser.py index d5552186ecc7..aecf69168f24 100644 --- a/mypy/config_parser.py +++ b/mypy/config_parser.py @@ -169,7 +169,7 @@ def parse_config_file(options: Options, set_strict_flags: Callable[[], None], try: if is_toml(config_file): with open(config_file, encoding="utf-8") as f: - toml_data = tomli.load(f) + toml_data = tomli.loads(f.read()) # Filter down to just mypy relevant toml keys toml_data = toml_data.get('tool', {}) if 'mypy' not in toml_data: diff --git a/mypy/modulefinder.py b/mypy/modulefinder.py index 131acb4d035a..18b62d0ff0df 100644 --- a/mypy/modulefinder.py +++ b/mypy/modulefinder.py @@ -439,8 +439,8 @@ def _is_compatible_stub_package(self, stub_dir: str) -> bool: if os.path.isfile(metadata_fnam): # Delay import for a possible minor performance win. import tomli - with open(metadata_fnam, 'r', encoding="utf-8") as f: - metadata = tomli.load(f) + with open(metadata_fnam, encoding="utf-8") as f: + metadata = tomli.loads(f.read()) if self.python_major_ver == 2: return bool(metadata.get('python2', False)) else: diff --git a/setup.py b/setup.py index 3d9461df9651..d3d1fb907f99 100644 --- a/setup.py +++ b/setup.py @@ -193,7 +193,7 @@ def run(self): install_requires=["typed_ast >= 1.4.0, < 2; python_version<'3.8'", 'typing_extensions>=3.7.4', 'mypy_extensions >= 0.4.3, < 0.5.0', - 'tomli>=1.1.0,<1.2.0', + 'tomli>=1.1.0,<2.0.0', ], # Same here. extras_require={'dmypy': 'psutil >= 4.0', 'python2': 'typed_ast >= 1.4.0, < 2'},