Skip to content

Commit 697c9dc

Browse files
authored
gh-108455: peg_generator: enable mypy's --warn-unreachable setting and redundant-expr error code (#109160)
1 parent 15d659f commit 697c9dc

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

Tools/peg_generator/mypy.ini

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@ python_version = 3.10
88

99
# Be strict...
1010
strict = True
11-
enable_error_code = truthy-bool,ignore-without-code
11+
warn_unreachable = True
12+
enable_error_code = truthy-bool,ignore-without-code,redundant-expr
1213

13-
# except for a few settings that can't yet be enabled:
14+
# This causes *many* false positives on the peg_generator
15+
# due to pegen.grammar.GrammarVisitor returning Any from visit() and generic_visit().
16+
# It would be possible to workaround the false positives using asserts,
17+
# but it would be pretty tedious, and probably isn't worth it.
1418
warn_return_any = False
15-
warn_unreachable = False
19+
20+
# Not all of the strictest settings can be enabled
21+
# on generated Python code yet:
22+
[mypy-pegen.grammar_parser.*]
23+
disable_error_code = redundant-expr

Tools/peg_generator/pegen/ast_dump.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,4 @@ def _format(node: Any, level: int = 0) -> Tuple[str, bool]:
6666

6767
if all(cls.__name__ != "AST" for cls in node.__class__.__mro__):
6868
raise TypeError("expected AST, got %r" % node.__class__.__name__)
69-
if indent is not None and not isinstance(indent, str):
70-
indent = " " * indent
7169
return _format(node)[0]

Tools/peg_generator/pegen/grammar.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ def __str__(self) -> str:
112112
return self.value
113113

114114
def __iter__(self) -> Iterable[str]:
115-
if False:
116-
yield
115+
yield from ()
117116

118117

119118
class NameLeaf(Leaf):
@@ -335,8 +334,7 @@ def __str__(self) -> str:
335334
return f"~"
336335

337336
def __iter__(self) -> Iterator[Tuple[str, str]]:
338-
if False:
339-
yield
337+
yield from ()
340338

341339
def __eq__(self, other: object) -> bool:
342340
if not isinstance(other, Cut):

0 commit comments

Comments
 (0)