From 8118ef6a45ff91da2924b97ae02aeb8535b600f8 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Sat, 12 Apr 2025 10:37:35 +0500 Subject: [PATCH 1/4] conformance - `subprocess.run` to use utf-8 to avoid issues on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was previously failing only for pyright but added it for all type checkers just to be sure. ``` Traceback (most recent call last): File "L:\Projects\Github\typing\conformance\src\main.py", line 260, in main() File "L:\Projects\Github\typing\conformance\src\main.py", line 253, in main run_tests(root_dir, type_checker, test_cases, skip_timing=options.skip_timing) File "L:\Projects\Github\typing\conformance\src\main.py", line 34, in run_tests type_checker.parse_errors(output.splitlines()) File "L:\Projects\Github\typing\conformance\src\type_checker.py", line 206, in parse_errors assert line.count(":") >= 3, f"Failed to parse line: {line!r}" ^^^^^^^^^^^^^^^^^^^^ AssertionError: Failed to parse line: 'Â\xa0Â\xa0Use list[T] to indicate a list type or T1 | T2 to indicate a union type (reportInvalidTypeForm)' ``` Update type_checker.py --- conformance/src/type_checker.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/conformance/src/type_checker.py b/conformance/src/type_checker.py index 21bec0d8f..09445ca64 100644 --- a/conformance/src/type_checker.py +++ b/conformance/src/type_checker.py @@ -114,7 +114,7 @@ def run_tests(self, test_files: Sequence[str]) -> dict[str, str]: "--enable-error-code", "deprecated", ] - proc = run(command, stdout=PIPE, text=True) + proc = run(command, stdout=PIPE, text=True, encoding="utf-8") lines = proc.stdout.split("\n") # Add results to a dictionary keyed by the file name. @@ -174,7 +174,7 @@ def get_version(self) -> str: def run_tests(self, test_files: Sequence[str]) -> dict[str, str]: command = [sys.executable, "-m", "pyright", ".", "--outputjson"] - proc = run(command, stdout=PIPE, text=True) + proc = run(command, stdout=PIPE, text=True, encoding="utf-8") output_json = json.loads(proc.stdout) diagnostics = output_json["generalDiagnostics"] @@ -253,7 +253,7 @@ def get_version(self) -> str: return version def run_tests(self, test_files: Sequence[str]) -> dict[str, str]: - proc = run(["pyre", "check"], stdout=PIPE, text=True) + proc = run(["pyre", "check"], stdout=PIPE, text=True, encoding="utf-8") lines = proc.stdout.split("\n") # Add results to a dictionary keyed by the file name. From 22bf371665b67e07a192adfdadf38dceb66098e3 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Sat, 12 Apr 2025 11:01:22 +0500 Subject: [PATCH 2/4] conformance - use utf-8 in `open` for Windows support On Windows it failed with UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 4590: character maps to --- conformance/src/main.py | 2 +- conformance/src/type_checker.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/conformance/src/main.py b/conformance/src/main.py index 02453f9f8..3f4b12973 100644 --- a/conformance/src/main.py +++ b/conformance/src/main.py @@ -67,7 +67,7 @@ def f(): pass # E[final] {"final": [3, 4]} ) """ - with open(test_case, "r") as f: + with open(test_case, "r", encoding="utf-8") as f: lines = f.readlines() output: dict[int, tuple[int, int]] = {} groups: dict[str, list[int]] = {} diff --git a/conformance/src/type_checker.py b/conformance/src/type_checker.py index 09445ca64..8bb31eef9 100644 --- a/conformance/src/type_checker.py +++ b/conformance/src/type_checker.py @@ -325,7 +325,7 @@ def run_tests(self, test_files: Sequence[str]) -> dict[str, str]: if not fi.endswith(".py"): continue options.tweak(input=fi) - with open(fi, "r") as test_file: + with open(fi, "r", encoding="utf-8") as test_file: src = test_file.read() try: analysis: pytype_analyze.Analysis = pytype_io.check_py( From ed2fbd3c532913878e8f89b7b72b9c662f888a7e Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Sat, 12 Apr 2025 11:23:30 +0500 Subject: [PATCH 3/4] conformance - enable pytype on Windows --- conformance/README.md | 2 +- conformance/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/conformance/README.md b/conformance/README.md index c5f04b0d1..a0a821359 100644 --- a/conformance/README.md +++ b/conformance/README.md @@ -60,7 +60,7 @@ To run the conformance test suite: * Switch to the `conformance` subdirectory and install all dependencies (`pip install -r requirements.txt`). * Switch to the `src` subdirectory and run `python main.py`. -Note that some type checkers may not run on some platforms. For example, pytype cannot be installed on Windows. If a type checker fails to install, tests will be skipped for that type checker. +Note that some type checkers may not run on some platforms. If a type checker fails to install, tests will be skipped for that type checker. ## Reporting Conformance Results diff --git a/conformance/requirements.txt b/conformance/requirements.txt index 396b5100d..d4c4d5a86 100644 --- a/conformance/requirements.txt +++ b/conformance/requirements.txt @@ -5,4 +5,4 @@ pyright mypy pip pyre-check -pytype; platform_system != "Windows" +pytype From 7ae980552c9db45f17c5b65b7ad57201fecf6351 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Sat, 12 Apr 2025 11:00:36 +0500 Subject: [PATCH 4/4] conformance - remove unused curses dependency Otherwise couldn't run conformance on Windows at all: ``` Traceback (most recent call last): File "L:\Projects\Github\typing\conformance\src\main.py", line 16, in from reporting import generate_summary File "L:\Projects\Github\typing\conformance\src\reporting.py", line 10, in from type_checker import TYPE_CHECKERS File "L:\Projects\Github\typing\conformance\src\type_checker.py", line 6, in from curses.ascii import isspace File "L:\Software\Python312\Lib\curses\__init__.py", line 13, in from _curses import * ModuleNotFoundError: No module named '_curses' ``` --- conformance/src/type_checker.py | 1 - 1 file changed, 1 deletion(-) diff --git a/conformance/src/type_checker.py b/conformance/src/type_checker.py index 8bb31eef9..d5ee0dfa7 100644 --- a/conformance/src/type_checker.py +++ b/conformance/src/type_checker.py @@ -3,7 +3,6 @@ """ from abc import ABC, abstractmethod -from curses.ascii import isspace import json from pathlib import Path import os