Skip to content

Commit ab7b69a

Browse files
authored
Support next types-setuptools update (#14781)
A simple type-only change since mypyc explicitely uses setuptools' monkeypatching. And `setup.py` imports from setuptools. Tests should stay the same. This should fix a sudden failure of tests once python/typeshed#9795 is merged.
1 parent 284142d commit ab7b69a

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

mypyc/build.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import re
2626
import sys
2727
import time
28-
from typing import TYPE_CHECKING, Any, Dict, Iterable, NoReturn, cast
28+
from typing import TYPE_CHECKING, Any, Dict, Iterable, NoReturn, Union, cast
2929

3030
from mypy.build import BuildSource
3131
from mypy.errors import CompileError
@@ -41,7 +41,13 @@
4141
from mypyc.options import CompilerOptions
4242

4343
if TYPE_CHECKING:
44-
from distutils.core import Extension
44+
from distutils.core import Extension as _distutils_Extension
45+
from typing_extensions import TypeAlias
46+
47+
from setuptools import Extension as _setuptools_Extension
48+
49+
Extension: TypeAlias = Union[_setuptools_Extension, _distutils_Extension]
50+
4551

4652
try:
4753
# Import setuptools so that it monkey-patch overrides distutils

setup.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import os.path
88
import sys
9+
from typing import TYPE_CHECKING, Any
910

1011
if sys.version_info < (3, 7, 0):
1112
sys.stderr.write("ERROR: You need Python 3.7 or later to use mypy.\n")
@@ -17,11 +18,14 @@
1718
# This requires setuptools when building; setuptools is not needed
1819
# when installing from a wheel file (though it is still needed for
1920
# alternative forms of installing, as suggested by README.md).
20-
from setuptools import find_packages, setup
21+
from setuptools import Extension, find_packages, setup
2122
from setuptools.command.build_py import build_py
2223

2324
from mypy.version import __version__ as version
2425

26+
if TYPE_CHECKING:
27+
from typing_extensions import TypeGuard
28+
2529
description = "Optional static typing for Python"
2630
long_description = """
2731
Mypy -- Optional Static Typing for Python
@@ -36,6 +40,10 @@
3640
""".lstrip()
3741

3842

43+
def is_list_of_setuptools_extension(items: list[Any]) -> TypeGuard[list[Extension]]:
44+
return all(isinstance(item, Extension) for item in items)
45+
46+
3947
def find_package_data(base, globs, root="mypy"):
4048
"""Find all interesting data files, for setup(package_data=)
4149
@@ -166,6 +174,8 @@ def run(self):
166174
# our Appveyor builds run out of memory sometimes.
167175
multi_file=sys.platform == "win32" or force_multifile,
168176
)
177+
assert is_list_of_setuptools_extension(ext_modules), "Expected mypycify to use setuptools"
178+
169179
else:
170180
ext_modules = []
171181

0 commit comments

Comments
 (0)