|
6 | 6 | import os
|
7 | 7 | import os.path
|
8 | 8 | import sys
|
| 9 | +from typing import TYPE_CHECKING, Any |
9 | 10 |
|
10 | 11 | if sys.version_info < (3, 7, 0):
|
11 | 12 | sys.stderr.write("ERROR: You need Python 3.7 or later to use mypy.\n")
|
|
17 | 18 | # This requires setuptools when building; setuptools is not needed
|
18 | 19 | # when installing from a wheel file (though it is still needed for
|
19 | 20 | # alternative forms of installing, as suggested by README.md).
|
20 |
| -from setuptools import find_packages, setup |
| 21 | +from setuptools import Extension, find_packages, setup |
21 | 22 | from setuptools.command.build_py import build_py
|
22 | 23 |
|
23 | 24 | from mypy.version import __version__ as version
|
24 | 25 |
|
| 26 | +if TYPE_CHECKING: |
| 27 | + from typing_extensions import TypeGuard |
| 28 | + |
25 | 29 | description = "Optional static typing for Python"
|
26 | 30 | long_description = """
|
27 | 31 | Mypy -- Optional Static Typing for Python
|
|
36 | 40 | """.lstrip()
|
37 | 41 |
|
38 | 42 |
|
| 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 | + |
39 | 47 | def find_package_data(base, globs, root="mypy"):
|
40 | 48 | """Find all interesting data files, for setup(package_data=)
|
41 | 49 |
|
@@ -166,6 +174,8 @@ def run(self):
|
166 | 174 | # our Appveyor builds run out of memory sometimes.
|
167 | 175 | multi_file=sys.platform == "win32" or force_multifile,
|
168 | 176 | )
|
| 177 | + assert is_list_of_setuptools_extension(ext_modules), "Expected mypycify to use setuptools" |
| 178 | + |
169 | 179 | else:
|
170 | 180 | ext_modules = []
|
171 | 181 |
|
|
0 commit comments