Skip to content

Commit 3aba4d4

Browse files
committed
Update mypy to 1.11
1 parent 48f95c0 commit 3aba4d4

File tree

7 files changed

+25
-13
lines changed

7 files changed

+25
-13
lines changed

mypy.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ disable_error_code = import-not-found
3838
[mypy-distutils._modified,jaraco.*,trove_classifiers,wheel.*]
3939
ignore_missing_imports = True
4040

41-
# Even when excluding generated modules, there might be problems: https://github.com/python/mypy/issues/11936#issuecomment-1466764006
41+
# Even when excluding a module, import issues can show up due to following import
42+
# https://github.com/python/mypy/issues/11936#issuecomment-1466764006
4243
[mypy-setuptools.config._validate_pyproject.*]
4344
follow_imports = silent
4445
# silent => ignore errors when following imports

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ test = [
5959
# for tools/finalize.py
6060
'jaraco.develop >= 7.21; python_version >= "3.9" and sys_platform != "cygwin"',
6161
"pytest-home >= 0.5",
62-
"mypy==1.10.0", # pin mypy version so a new version doesn't suddenly cause the CI to fail
62+
# pin mypy version so a new version doesn't suddenly cause the CI to fail,
63+
# until types-setuptools is removed from typeshed.
64+
# For help with static-typing issues, or mypy update, ping @Avasam
65+
"mypy==1.11",
6366
# No Python 3.11 dependencies require tomli, but needed for type-checking since we import it directly
6467
"tomli",
6568
# No Python 3.12 dependencies require importlib_metadata, but needed for type-checking since we import it directly

setuptools/command/editable_wheel.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,7 @@ def __init__(
443443
):
444444
self.auxiliary_dir = Path(auxiliary_dir)
445445
self.build_lib = Path(build_lib).resolve()
446-
# TODO: Update typeshed distutils stubs to overload non-None return type by default
447-
self._file = dist.get_command_obj("build_py").copy_file # type: ignore[union-attr]
446+
self._file = dist.get_command_obj("build_py").copy_file
448447
super().__init__(dist, name, [self.auxiliary_dir])
449448

450449
def __call__(self, wheel: WheelFile, files: list[str], mapping: dict[str, str]):
@@ -462,9 +461,7 @@ def _create_file(self, relative_output: str, src_file: str, link=None):
462461
dest = self.auxiliary_dir / relative_output
463462
if not dest.parent.is_dir():
464463
dest.parent.mkdir(parents=True)
465-
# TODO: Update typeshed distutils stubs so distutils.cmd.Command.copy_file, accepts PathLike
466-
# same with methods used by copy_file
467-
self._file(src_file, dest, link=link) # type: ignore[arg-type]
464+
self._file(src_file, dest, link=link)
468465

469466
def _create_links(self, outputs, output_mapping):
470467
self.auxiliary_dir.mkdir(parents=True, exist_ok=True)

setuptools/command/install.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
from __future__ import annotations
2+
3+
from collections.abc import Callable
14
from distutils.errors import DistutilsArgError
25
import inspect
36
import glob
47
import platform
58
import distutils.command.install as orig
6-
from typing import cast
9+
from typing import Any, ClassVar, cast
710

811
import setuptools
912
from ..warnings import SetuptoolsDeprecationWarning, SetuptoolsWarning
@@ -29,7 +32,9 @@ class install(orig.install):
2932
'old-and-unmanageable',
3033
'single-version-externally-managed',
3134
]
32-
new_commands = [
35+
# Type the same as distutils.command.install.install.sub_commands
36+
# Must keep the second tuple item potentially None due to invariance
37+
new_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]] = [
3338
('install_egg_info', lambda self: True),
3439
('install_scripts', lambda self: True),
3540
]

setuptools/command/install_lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def copy_tree(
9797
exclude = self.get_exclusions()
9898

9999
if not exclude:
100-
return orig.install_lib.copy_tree(self, infile, outfile) # type: ignore[arg-type] # Fixed upstream
100+
return orig.install_lib.copy_tree(self, infile, outfile)
101101

102102
# Exclude namespace package __init__.py* files from the output
103103

setuptools/command/upload_docs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def has_sphinx(self):
5050
and metadata.entry_points(group='distutils.commands', name='build_sphinx')
5151
)
5252

53-
sub_commands = [('build_sphinx', has_sphinx)] # type: ignore[list-item] # TODO: Fix in typeshed distutils stubs
53+
sub_commands = [('build_sphinx', has_sphinx)]
5454

5555
def initialize_options(self):
5656
upload.initialize_options(self)

setuptools/tests/test_wheel.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""wheel tests"""
22

3+
from __future__ import annotations
4+
35
from distutils.sysconfig import get_config_var
46
from distutils.util import get_platform
57
import contextlib
@@ -11,6 +13,7 @@
1113
import shutil
1214
import subprocess
1315
import sys
16+
from typing import Any
1417
import zipfile
1518

1619
import pytest
@@ -176,7 +179,10 @@ def __repr__(self):
176179
return '%s(**%r)' % (self._id, self._fields)
177180

178181

179-
WHEEL_INSTALL_TESTS = (
182+
# Using Any to avoid possible type union issues later in test
183+
# making a TypedDict is not worth in a test and anonymous/inline TypedDict are experimental
184+
# https://github.com/python/mypy/issues/9884
185+
WHEEL_INSTALL_TESTS: tuple[dict[str, Any], ...] = (
180186
dict(
181187
id='basic',
182188
file_defs={'foo': {'__init__.py': ''}},
@@ -547,7 +553,7 @@ def __repr__(self):
547553
@pytest.mark.parametrize(
548554
'params',
549555
WHEEL_INSTALL_TESTS,
550-
ids=list(params['id'] for params in WHEEL_INSTALL_TESTS),
556+
ids=[params['id'] for params in WHEEL_INSTALL_TESTS],
551557
)
552558
def test_wheel_install(params):
553559
project_name = params.get('name', 'foo')

0 commit comments

Comments
 (0)