Skip to content

Commit 77e8f23

Browse files
authored
gh-108455: peg_generator: install two stubs packages before running mypy (#108637)
1 parent 8178a88 commit 77e8f23

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

Tools/peg_generator/mypy.ini

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ enable_error_code = truthy-bool,ignore-without-code
1414
warn_return_any = False
1515
warn_unreachable = False
1616

17-
[mypy-setuptools.*]
18-
ignore_missing_imports = True
17+
[mypy-pegen.build]
18+
# we need this for now due to some missing annotations
19+
# in typeshed's stubs for setuptools
20+
disallow_untyped_calls = False

Tools/peg_generator/pegen/build.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import itertools
2+
import logging
23
import os
34
import pathlib
45
import sys
@@ -90,6 +91,7 @@ def compile_c_extension(
9091
static library of the common parser sources (this is useful in case you are
9192
creating multiple extensions).
9293
"""
94+
import setuptools.command.build_ext
9395
import setuptools.logging
9496

9597
from setuptools import Extension, Distribution
@@ -98,7 +100,7 @@ def compile_c_extension(
98100
from setuptools._distutils.sysconfig import customize_compiler
99101

100102
if verbose:
101-
setuptools.logging.set_threshold(setuptools.logging.logging.DEBUG)
103+
setuptools.logging.set_threshold(logging.DEBUG)
102104

103105
source_file_path = pathlib.Path(generated_source_path)
104106
extension_name = source_file_path.stem
@@ -140,12 +142,14 @@ def compile_c_extension(
140142
)
141143
dist = Distribution({"name": extension_name, "ext_modules": [extension]})
142144
cmd = dist.get_command_obj("build_ext")
145+
assert isinstance(cmd, setuptools.command.build_ext.build_ext)
143146
fixup_build_ext(cmd)
144147
cmd.build_lib = str(source_file_path.parent)
145148
cmd.include_dirs = include_dirs
146149
if build_dir:
147150
cmd.build_temp = build_dir
148-
cmd.ensure_finalized()
151+
# A deficiency in typeshed's stubs means we have to type: ignore:
152+
cmd.ensure_finalized() # type: ignore[attr-defined]
149153

150154
compiler = new_compiler()
151155
customize_compiler(compiler)
@@ -156,7 +160,8 @@ def compile_c_extension(
156160
library_filename = compiler.library_filename(extension_name, output_dir=library_dir)
157161
if newer_group(common_sources, library_filename, "newer"):
158162
if sys.platform == "win32":
159-
pdb = compiler.static_lib_format % (extension_name, ".pdb")
163+
# A deficiency in typeshed's stubs means we have to type: ignore:
164+
pdb = compiler.static_lib_format % (extension_name, ".pdb") # type: ignore[attr-defined]
160165
compile_opts = [f"/Fd{library_dir}\\{pdb}"]
161166
compile_opts.extend(extra_compile_args)
162167
else:

Tools/peg_generator/pegen/testutil.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def generate_parser_c_extension(
116116
def print_memstats() -> bool:
117117
MiB: Final = 2**20
118118
try:
119-
import psutil # type: ignore[import]
119+
import psutil
120120
except ImportError:
121121
return False
122122
print("Memory stats:")

Tools/requirements-dev.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# Requirements file for external linters and checks we run on
22
# Tools/clinic, Tools/cases_generator/, and Tools/peg_generator/ in CI
33
mypy==1.5.1
4+
5+
# needed for peg_generator:
6+
types-psutil==5.9.5.16
7+
types-setuptools==68.1.0.0

0 commit comments

Comments
 (0)