diff --git a/Tools/peg_generator/mypy.ini b/Tools/peg_generator/mypy.ini index 3f3db2ea1266c6..55429dd76eba68 100644 --- a/Tools/peg_generator/mypy.ini +++ b/Tools/peg_generator/mypy.ini @@ -14,5 +14,7 @@ enable_error_code = truthy-bool,ignore-without-code warn_return_any = False warn_unreachable = False -[mypy-setuptools.*] -ignore_missing_imports = True +[mypy-pegen.build] +# we need this for now due to some missing annotations +# in typeshed's stubs for setuptools +disallow_untyped_calls = False diff --git a/Tools/peg_generator/pegen/build.py b/Tools/peg_generator/pegen/build.py index 81efcadc001ec5..998cd41428db19 100644 --- a/Tools/peg_generator/pegen/build.py +++ b/Tools/peg_generator/pegen/build.py @@ -1,4 +1,5 @@ import itertools +import logging import os import pathlib import sys @@ -90,6 +91,7 @@ def compile_c_extension( static library of the common parser sources (this is useful in case you are creating multiple extensions). """ + import setuptools.command.build_ext import setuptools.logging from setuptools import Extension, Distribution @@ -98,7 +100,7 @@ def compile_c_extension( from setuptools._distutils.sysconfig import customize_compiler if verbose: - setuptools.logging.set_threshold(setuptools.logging.logging.DEBUG) + setuptools.logging.set_threshold(logging.DEBUG) source_file_path = pathlib.Path(generated_source_path) extension_name = source_file_path.stem @@ -140,12 +142,14 @@ def compile_c_extension( ) dist = Distribution({"name": extension_name, "ext_modules": [extension]}) cmd = dist.get_command_obj("build_ext") + assert isinstance(cmd, setuptools.command.build_ext.build_ext) fixup_build_ext(cmd) cmd.build_lib = str(source_file_path.parent) cmd.include_dirs = include_dirs if build_dir: cmd.build_temp = build_dir - cmd.ensure_finalized() + # A deficiency in typeshed's stubs means we have to type: ignore: + cmd.ensure_finalized() # type: ignore[attr-defined] compiler = new_compiler() customize_compiler(compiler) @@ -156,7 +160,8 @@ def compile_c_extension( library_filename = compiler.library_filename(extension_name, output_dir=library_dir) if newer_group(common_sources, library_filename, "newer"): if sys.platform == "win32": - pdb = compiler.static_lib_format % (extension_name, ".pdb") + # A deficiency in typeshed's stubs means we have to type: ignore: + pdb = compiler.static_lib_format % (extension_name, ".pdb") # type: ignore[attr-defined] compile_opts = [f"/Fd{library_dir}\\{pdb}"] compile_opts.extend(extra_compile_args) else: diff --git a/Tools/peg_generator/pegen/testutil.py b/Tools/peg_generator/pegen/testutil.py index 50cc8520f2ce3f..0e85b844ef152b 100644 --- a/Tools/peg_generator/pegen/testutil.py +++ b/Tools/peg_generator/pegen/testutil.py @@ -116,7 +116,7 @@ def generate_parser_c_extension( def print_memstats() -> bool: MiB: Final = 2**20 try: - import psutil # type: ignore[import] + import psutil except ImportError: return False print("Memory stats:") diff --git a/Tools/requirements-dev.txt b/Tools/requirements-dev.txt index b814169974bd08..49f783c096f2d2 100644 --- a/Tools/requirements-dev.txt +++ b/Tools/requirements-dev.txt @@ -1,3 +1,7 @@ # Requirements file for external linters and checks we run on # Tools/clinic, Tools/cases_generator/, and Tools/peg_generator/ in CI mypy==1.5.1 + +# needed for peg_generator: +types-psutil==5.9.5.16 +types-setuptools==68.1.0.0