Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mypy to 1.11 #4500

Merged
merged 2 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ disable_error_code = import-not-found
[mypy-distutils._modified,jaraco.*,trove_classifiers,wheel.*]
ignore_missing_imports = True

# Even when excluding generated modules, there might be problems: https://github.com/python/mypy/issues/11936#issuecomment-1466764006
# Even when excluding a module, import issues can show up due to following import
# https://github.com/python/mypy/issues/11936#issuecomment-1466764006
[mypy-setuptools.config._validate_pyproject.*]
follow_imports = silent
# silent => ignore errors when following imports
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ test = [
# for tools/finalize.py
'jaraco.develop >= 7.21; python_version >= "3.9" and sys_platform != "cygwin"',
"pytest-home >= 0.5",
"mypy==1.10.0", # pin mypy version so a new version doesn't suddenly cause the CI to fail
# pin mypy version so a new version doesn't suddenly cause the CI to fail,
# until types-setuptools is removed from typeshed.
# For help with static-typing issues, or mypy update, ping @Avasam
"mypy==1.11",
Avasam marked this conversation as resolved.
Show resolved Hide resolved
# No Python 3.11 dependencies require tomli, but needed for type-checking since we import it directly
"tomli",
# No Python 3.12 dependencies require importlib_metadata, but needed for type-checking since we import it directly
Expand Down
7 changes: 2 additions & 5 deletions setuptools/command/editable_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,7 @@ def __init__(
):
self.auxiliary_dir = Path(auxiliary_dir)
self.build_lib = Path(build_lib).resolve()
# TODO: Update typeshed distutils stubs to overload non-None return type by default
self._file = dist.get_command_obj("build_py").copy_file # type: ignore[union-attr]
self._file = dist.get_command_obj("build_py").copy_file
super().__init__(dist, name, [self.auxiliary_dir])

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

def _create_links(self, outputs, output_mapping):
self.auxiliary_dir.mkdir(parents=True, exist_ok=True)
Expand Down
9 changes: 7 additions & 2 deletions setuptools/command/install.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from __future__ import annotations

from collections.abc import Callable
from distutils.errors import DistutilsArgError
import inspect
import glob
import platform
import distutils.command.install as orig
from typing import cast
from typing import Any, ClassVar, cast

import setuptools
from ..warnings import SetuptoolsDeprecationWarning, SetuptoolsWarning
Expand All @@ -29,7 +32,9 @@ class install(orig.install):
'old-and-unmanageable',
'single-version-externally-managed',
]
new_commands = [
# Type the same as distutils.command.install.install.sub_commands
# Must keep the second tuple item potentially None due to invariance
new_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]] = [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was causing invariance issues when trying to append install.new_commands to install.sub_commands at the end of this module

('install_egg_info', lambda self: True),
('install_scripts', lambda self: True),
]
Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/install_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def copy_tree(
exclude = self.get_exclusions()

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

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

Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/upload_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def has_sphinx(self):
and metadata.entry_points(group='distutils.commands', name='build_sphinx')
)

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

def initialize_options(self):
upload.initialize_options(self)
Expand Down
10 changes: 8 additions & 2 deletions setuptools/tests/test_wheel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""wheel tests"""

from __future__ import annotations

from distutils.sysconfig import get_config_var
from distutils.util import get_platform
import contextlib
Expand All @@ -11,6 +13,7 @@
import shutil
import subprocess
import sys
from typing import Any
import zipfile

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


WHEEL_INSTALL_TESTS = (
# Using Any to avoid possible type union issues later in test
# making a TypedDict is not worth in a test and anonymous/inline TypedDict are experimental
# https://github.com/python/mypy/issues/9884
WHEEL_INSTALL_TESTS: tuple[dict[str, Any], ...] = (
dict(
id='basic',
file_defs={'foo': {'__init__.py': ''}},
Expand Down Expand Up @@ -547,7 +553,7 @@ def __repr__(self):
@pytest.mark.parametrize(
'params',
WHEEL_INSTALL_TESTS,
ids=list(params['id'] for params in WHEEL_INSTALL_TESTS),
ids=[params['id'] for params in WHEEL_INSTALL_TESTS],
Copy link
Contributor Author

@Avasam Avasam Jul 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a necessary change, but I noticed this improvement whilst I was looking at this line. After realizing the best fix was an annotation change, I left this line as a comprehension. Would've been caught by https://docs.astral.sh/ruff/rules/unnecessary-generator-list/

I can revert this line if you'd prefer no runtime change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with it. Thanks for highlighting!

)
def test_wheel_install(params):
project_name = params.get('name', 'foo')
Expand Down
Loading