From 02bbe71a93c0d4b00440239b7c46c5d3b08e2b90 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Date: Fri, 30 Jul 2021 09:24:06 +0300 Subject: [PATCH 1/3] Disable universal newlines when reading TOML --- mypy-requirements.txt | 2 +- mypy/config_parser.py | 2 +- mypy/modulefinder.py | 2 +- setup.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mypy-requirements.txt b/mypy-requirements.txt index e7e2af80089bb..784cc81f3ec1a 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,<1.5.0 -tomli<2.0.0 +tomli>=1.1.0,<2.0.0 diff --git a/mypy/config_parser.py b/mypy/config_parser.py index d5552186ecc70..8f12427194535 100644 --- a/mypy/config_parser.py +++ b/mypy/config_parser.py @@ -168,7 +168,7 @@ def parse_config_file(options: Options, set_strict_flags: Callable[[], None], continue try: if is_toml(config_file): - with open(config_file, encoding="utf-8") as f: + with open(config_file, "rb") as f: toml_data = tomli.load(f) # Filter down to just mypy relevant toml keys toml_data = toml_data.get('tool', {}) diff --git a/mypy/modulefinder.py b/mypy/modulefinder.py index 6cebd7db8bc0b..e8a748bab12b4 100644 --- a/mypy/modulefinder.py +++ b/mypy/modulefinder.py @@ -434,7 +434,7 @@ 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: + with open(metadata_fnam, 'rb') as f: metadata = tomli.load(f) if self.python_major_ver == 2: return bool(metadata.get('python2', False)) diff --git a/setup.py b/setup.py index 50974068a84c1..eef7f4ba2732e 100644 --- a/setup.py +++ b/setup.py @@ -193,7 +193,7 @@ def run(self): install_requires=["typed_ast >= 1.4.0, < 1.5.0; python_version<'3.8'", 'typing_extensions>=3.7.4', 'mypy_extensions >= 0.4.3, < 0.5.0', - 'tomli<2.0.0', + 'tomli>=1.1.0,<2.0.0', ], # Same here. extras_require={'dmypy': 'psutil >= 4.0', 'python2': 'typed_ast >= 1.4.0, < 1.5.0'}, From 5fee414b144a80d859ada2b33bff5efb43bb101e Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Wed, 1 Dec 2021 17:45:33 +0000 Subject: [PATCH 2/3] Update mypy/modulefinder.py Co-authored-by: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> --- mypy/modulefinder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mypy/modulefinder.py b/mypy/modulefinder.py index 1db55ee27a608..8dcaee6f99d6c 100644 --- a/mypy/modulefinder.py +++ b/mypy/modulefinder.py @@ -451,8 +451,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, 'rb') 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: From 98fea60fe511f6ce32715e46e27196cd52145b9e Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Wed, 1 Dec 2021 17:45:54 +0000 Subject: [PATCH 3/3] Update mypy/config_parser.py Co-authored-by: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> --- mypy/config_parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mypy/config_parser.py b/mypy/config_parser.py index 4dbf091a857c9..24e61df0441c0 100644 --- a/mypy/config_parser.py +++ b/mypy/config_parser.py @@ -171,8 +171,8 @@ def parse_config_file(options: Options, set_strict_flags: Callable[[], None], continue try: if is_toml(config_file): - with open(config_file, "rb") as f: - toml_data = tomli.load(f) + with open(config_file, encoding="utf-8") as 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: