Skip to content

Commit c08b596

Browse files
committed
pythongh-108455: Run mypy on Tools/peg_generator
1 parent a071ecb commit c08b596

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

.github/workflows/mypy.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
paths:
1010
- "Tools/clinic/**"
1111
- "Tools/cases_generator/**"
12+
- "Tools/peg_generator/**"
1213
- ".github/workflows/mypy.yml"
1314
workflow_dispatch:
1415

@@ -28,7 +29,11 @@ jobs:
2829
mypy:
2930
strategy:
3031
matrix:
31-
target: ["Tools/cases_generator", "Tools/clinic"]
32+
target: [
33+
"Tools/cases_generator",
34+
"Tools/clinic",
35+
"Tools/peg_generator",
36+
]
3237
name: Run mypy on ${{ matrix.target }}
3338
runs-on: ubuntu-latest
3439
timeout-minutes: 10

Tools/peg_generator/mypy.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[mypy]
2-
files = pegen
2+
files = Tools/peg_generator/pegen
3+
pretty = True
34

45
follow_imports = error
56
no_implicit_optional = True

Tools/peg_generator/pegen/build.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sysconfig
66
import tempfile
77
import tokenize
8-
from typing import IO, Dict, List, Optional, Set, Tuple
8+
from typing import IO, Any, Dict, List, Optional, Set, Tuple
99

1010
from pegen.c_generator import CParserGenerator
1111
from pegen.grammar import Grammar
@@ -18,6 +18,7 @@
1818
MOD_DIR = pathlib.Path(__file__).resolve().parent
1919

2020
TokenDefinitions = Tuple[Dict[int, str], Dict[str, int], Set[str]]
21+
Incomplete = Any # TODO: install `types-setuptools` and remove this alias
2122

2223

2324
def get_extra_flags(compiler_flags: str, compiler_py_flags_nodist: str) -> List[str]:
@@ -28,7 +29,7 @@ def get_extra_flags(compiler_flags: str, compiler_py_flags_nodist: str) -> List[
2829
return f"{flags} {py_flags_nodist}".split()
2930

3031

31-
def fixup_build_ext(cmd):
32+
def fixup_build_ext(cmd: Incomplete) -> None:
3233
"""Function needed to make build_ext tests pass.
3334
3435
When Python was built with --enable-shared on Unix, -L. is not enough to
@@ -74,7 +75,7 @@ def compile_c_extension(
7475
keep_asserts: bool = True,
7576
disable_optimization: bool = False,
7677
library_dir: Optional[str] = None,
77-
) -> str:
78+
) -> pathlib.Path:
7879
"""Compile the generated source for a parser generator into an extension module.
7980
8081
The extension module will be generated in the same directory as the provided path
@@ -89,12 +90,12 @@ def compile_c_extension(
8990
static library of the common parser sources (this is useful in case you are
9091
creating multiple extensions).
9192
"""
92-
import setuptools.logging
93+
import setuptools.logging # type: ignore[import]
9394

9495
from setuptools import Extension, Distribution
95-
from setuptools._distutils.dep_util import newer_group
96-
from setuptools._distutils.ccompiler import new_compiler
97-
from setuptools._distutils.sysconfig import customize_compiler
96+
from setuptools._distutils.dep_util import newer_group # type: ignore[import]
97+
from setuptools._distutils.ccompiler import new_compiler # type: ignore[import]
98+
from setuptools._distutils.sysconfig import customize_compiler # type: ignore[import]
9899

99100
if verbose:
100101
setuptools.logging.set_threshold(setuptools.logging.logging.DEBUG)

Tools/peg_generator/pegen/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def logger(method: F) -> F:
2121
"""
2222
method_name = method.__name__
2323

24-
def logger_wrapper(self: P, *args: object) -> T:
24+
def logger_wrapper(self: P, *args: object) -> Any:
2525
if not self._verbose:
2626
return method(self, *args)
2727
argsr = ",".join(repr(arg) for arg in args)
@@ -41,7 +41,7 @@ def memoize(method: F) -> F:
4141
"""Memoize a symbol method."""
4242
method_name = method.__name__
4343

44-
def memoize_wrapper(self: P, *args: object) -> T:
44+
def memoize_wrapper(self: P, *args: object) -> Any:
4545
mark = self._mark()
4646
key = mark, method_name, args
4747
# Fast path: cache hit, and not verbose.

Tools/requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Requirements file for external linters and checks we run on
2-
# Tools/clinic and Tools/cases_generator/ in CI
2+
# Tools/clinic, Tools/cases_generator/, and Tools/peg_generator/ in CI
33
mypy==1.5.1

0 commit comments

Comments
 (0)