From 88354a903af6fc69b599fafe57506d1f03c37b7c Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 3 Jan 2022 18:39:32 +0000 Subject: [PATCH 1/3] Make mypy test suite pass mypy on Windows --- mypy/test/data.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/mypy/test/data.py b/mypy/test/data.py index e886b11ffa8e..721d9172680b 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -10,10 +10,26 @@ import sys import pytest -from typing import List, Tuple, Set, Optional, Iterator, Any, Dict, NamedTuple, Union +from typing import ( + List, + Protocol, + Tuple, + TYPE_CHECKING, + Set, + Optional, + Iterator, + Any, + Dict, + NamedTuple, + Union, + overload +) from mypy.test.config import test_data_prefix, test_temp_dir, PREFIX +if TYPE_CHECKING: + from _typeshed import BytesPath, StrPath + root_dir = os.path.normpath(PREFIX) # File modify/create operation: copy module contents from source_path. @@ -28,6 +44,18 @@ FileOperation = Union[UpdateFile, DeleteFile] +class JoinFunction(Protocol): + """A callback protocol with which both `ntpath.join()` and `posixpath.join()` are compliant. + + The two functions have different parameter names, + meaning this file doesn't type-check on Windows without this protocol. + """ + @overload + def __call__(self, __path: 'StrPath', *paths: 'StrPath') -> str: ... + @overload + def __call__(self, __path: 'BytesPath', *paths: 'BytesPath') -> bytes: ... + + def parse_test_case(case: 'DataDrivenTestCase') -> None: """Parse and prepare a single case from suite with test case descriptions. @@ -35,6 +63,7 @@ def parse_test_case(case: 'DataDrivenTestCase') -> None: """ test_items = parse_test_data(case.data, case.name) base_path = case.suite.base_path + join: JoinFunction if case.suite.native_sep: join = os.path.join else: From 44f9eb7f4183804aab6734972e5941aef89c7405 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 3 Jan 2022 18:58:23 +0000 Subject: [PATCH 2/3] Update data.py --- mypy/test/data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/test/data.py b/mypy/test/data.py index 721d9172680b..be5b0cea3bf4 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -12,7 +12,6 @@ import pytest from typing import ( List, - Protocol, Tuple, TYPE_CHECKING, Set, @@ -24,6 +23,7 @@ Union, overload ) +from typing_extensions import Protocol from mypy.test.config import test_data_prefix, test_temp_dir, PREFIX From 4be969d8ade43c8f8391e21cbb4adedde171e275 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 4 Jan 2022 08:31:44 +0000 Subject: [PATCH 3/3] Update data.py --- mypy/test/data.py | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/mypy/test/data.py b/mypy/test/data.py index be5b0cea3bf4..c4eefad6592c 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -10,26 +10,10 @@ import sys import pytest -from typing import ( - List, - Tuple, - TYPE_CHECKING, - Set, - Optional, - Iterator, - Any, - Dict, - NamedTuple, - Union, - overload -) -from typing_extensions import Protocol +from typing import Callable, List, Tuple, Set, Optional, Iterator, Any, Dict, NamedTuple, Union from mypy.test.config import test_data_prefix, test_temp_dir, PREFIX -if TYPE_CHECKING: - from _typeshed import BytesPath, StrPath - root_dir = os.path.normpath(PREFIX) # File modify/create operation: copy module contents from source_path. @@ -44,18 +28,6 @@ FileOperation = Union[UpdateFile, DeleteFile] -class JoinFunction(Protocol): - """A callback protocol with which both `ntpath.join()` and `posixpath.join()` are compliant. - - The two functions have different parameter names, - meaning this file doesn't type-check on Windows without this protocol. - """ - @overload - def __call__(self, __path: 'StrPath', *paths: 'StrPath') -> str: ... - @overload - def __call__(self, __path: 'BytesPath', *paths: 'BytesPath') -> bytes: ... - - def parse_test_case(case: 'DataDrivenTestCase') -> None: """Parse and prepare a single case from suite with test case descriptions. @@ -63,7 +35,8 @@ def parse_test_case(case: 'DataDrivenTestCase') -> None: """ test_items = parse_test_data(case.data, case.name) base_path = case.suite.base_path - join: JoinFunction + # this file doesn't type-check on Windows without this line, see #11895 + join: Callable[[str, str], str] if case.suite.native_sep: join = os.path.join else: