Skip to content

Commit f410da1

Browse files
authored
Fix mypy failure after multiple merges (#4726)
2 parents 39179c1 + e5ec6fd commit f410da1

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

setuptools/command/install.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import inspect
55
import platform
66
from collections.abc import Callable
7-
from typing import Any, ClassVar, cast
7+
from typing import TYPE_CHECKING, Any, ClassVar, cast
88

99
import setuptools
1010

@@ -15,6 +15,12 @@
1515
import distutils.command.install as orig
1616
from distutils.errors import DistutilsArgError
1717

18+
if TYPE_CHECKING:
19+
# This is only used for a type-cast, don't import at runtime or it'll cause deprecation warnings
20+
from .easy_install import easy_install as easy_install_cls
21+
else:
22+
easy_install_cls = None
23+
1824
# Prior to numpy 1.9, NumPy relies on the '_install' name, so provide it for
1925
# now. See https://github.com/pypa/setuptools/issues/199/
2026
_install = orig.install
@@ -133,11 +139,17 @@ def _called_from_setup(run_frame):
133139
def do_egg_install(self) -> None:
134140
easy_install = self.distribution.get_command_class('easy_install')
135141

136-
cmd = easy_install(
137-
self.distribution,
138-
args="x",
139-
root=self.root,
140-
record=self.record,
142+
cmd = cast(
143+
# We'd want to cast easy_install as type[easy_install_cls] but a bug in
144+
# mypy makes it think easy_install() returns a Command on Python 3.12+
145+
# https://github.com/python/mypy/issues/18088
146+
easy_install_cls,
147+
easy_install( # type: ignore[call-arg]
148+
self.distribution,
149+
args="x",
150+
root=self.root,
151+
record=self.record,
152+
),
141153
)
142154
cmd.ensure_finalized() # finalize before bdist_egg munges install cmd
143155
cmd.always_copy_from = '.' # make sure local-dir eggs get installed

0 commit comments

Comments
 (0)