Skip to content

Commit eddd9dd

Browse files
Enable mypy's strict equality checks (#12209)
This makes mypy check more behaviours within the codebase. Co-authored-by: Pradyun Gedam <[email protected]>
1 parent 4b0e7e5 commit eddd9dd

File tree

8 files changed

+21
-17
lines changed

8 files changed

+21
-17
lines changed

news/E2B261CA-A0CF-4309-B808-1210C0B54632.trivial.rst

Whitespace-only changes.

setup.cfg

+7-4
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ per-file-ignores =
3636

3737
[mypy]
3838
mypy_path = $MYPY_CONFIG_FILE_DIR/src
39+
40+
strict = True
41+
42+
no_implicit_reexport = False
43+
allow_subclassing_any = True
44+
allow_untyped_calls = True
45+
warn_return_any = False
3946
ignore_missing_imports = True
40-
disallow_untyped_defs = True
41-
disallow_any_generics = True
42-
warn_unused_ignores = True
43-
no_implicit_optional = True
4447

4548
[mypy-pip._internal.utils._jaraco_text]
4649
ignore_errors = True

src/pip/_internal/utils/temp_dir.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import traceback
77
from contextlib import ExitStack, contextmanager
88
from pathlib import Path
9-
from types import FunctionType
109
from typing import (
1110
Any,
11+
Callable,
1212
Dict,
1313
Generator,
1414
List,
@@ -187,7 +187,7 @@ def cleanup(self) -> None:
187187
errors: List[BaseException] = []
188188

189189
def onerror(
190-
func: FunctionType,
190+
func: Callable[..., Any],
191191
path: Path,
192192
exc_val: BaseException,
193193
) -> None:

tests/functional/test_list.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,7 @@ def test_outdated_formats(script: PipTestEnvironment, data: TestData) -> None:
595595
"--outdated",
596596
"--format=json",
597597
)
598-
data = json.loads(result.stdout)
599-
assert data == [
598+
assert json.loads(result.stdout) == [
600599
{
601600
"name": "simple",
602601
"version": "1.0",

tests/lib/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
# Literal was introduced in Python 3.8.
4747
from typing import Literal
4848

49-
ResolverVariant = Literal["resolvelib", "legacy"]
49+
ResolverVariant = Literal[
50+
"resolvelib", "legacy", "2020-resolver", "legacy-resolver"
51+
]
5052
else:
5153
ResolverVariant = str
5254

tests/unit/test_network_auth.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def get_credential(self, system: str, username: str) -> Optional[Credential]:
352352
),
353353
)
354354
def test_keyring_get_credential(
355-
monkeypatch: pytest.MonkeyPatch, url: str, expect: str
355+
monkeypatch: pytest.MonkeyPatch, url: str, expect: Tuple[str, str]
356356
) -> None:
357357
monkeypatch.setitem(sys.modules, "keyring", KeyringModuleV2())
358358
auth = MultiDomainBasicAuth(

tests/unit/test_options.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from contextlib import contextmanager
33
from optparse import Values
44
from tempfile import NamedTemporaryFile
5-
from typing import Any, Dict, Iterator, List, Tuple, Union, cast
5+
from typing import Any, Dict, Iterator, List, Tuple, Type, Union, cast
66

77
import pytest
88

@@ -605,7 +605,7 @@ def test_config_file_options(
605605
self,
606606
monkeypatch: pytest.MonkeyPatch,
607607
args: List[str],
608-
expect: Union[None, str, PipError],
608+
expect: Union[None, str, Type[PipError]],
609609
) -> None:
610610
cmd = cast(ConfigurationCommand, create_command("config"))
611611
# Replace a handler with a no-op to avoid side effects

tests/unit/test_target_python.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,17 @@ def test_get_sorted_tags(
9999
py_version_info: Optional[Tuple[int, ...]],
100100
expected_version: Optional[str],
101101
) -> None:
102-
mock_get_supported.return_value = ["tag-1", "tag-2"]
102+
dummy_tags = [Tag("py4", "none", "any"), Tag("py5", "none", "any")]
103+
mock_get_supported.return_value = dummy_tags
103104

104105
target_python = TargetPython(py_version_info=py_version_info)
105106
actual = target_python.get_sorted_tags()
106-
assert actual == ["tag-1", "tag-2"]
107+
assert actual == dummy_tags
107108

108-
actual = mock_get_supported.call_args[1]["version"]
109-
assert actual == expected_version
109+
assert mock_get_supported.call_args[1]["version"] == expected_version
110110

111111
# Check that the value was cached.
112-
assert target_python._valid_tags == ["tag-1", "tag-2"]
112+
assert target_python._valid_tags == dummy_tags
113113

114114
def test_get_unsorted_tags__uses_cached_value(self) -> None:
115115
"""

0 commit comments

Comments
 (0)