Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 818c83c

Browse filesBrowse files
authored
gh-104683: Argument clinic: cleanup DLSParser state_foo methods (#107543)
1 parent c8872f4 commit 818c83c
Copy full SHA for 818c83c

File tree

Expand file treeCollapse file tree

1 file changed

+11
-22
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-22
lines changed

‎Tools/clinic/clinic.py

Copy file name to clipboardExpand all lines: Tools/clinic/clinic.py
+11-22Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
NamedTuple,
4646
NoReturn,
4747
Protocol,
48-
TypeGuard,
4948
TypeVar,
5049
cast,
5150
overload,
@@ -4388,7 +4387,7 @@ def dedent(self, line: str) -> str:
43884387
return line[indent:]
43894388

43904389

4391-
StateKeeper = Callable[[str | None], None]
4390+
StateKeeper = Callable[[str], None]
43924391
ConverterArgs = dict[str, Any]
43934392

43944393
class ParamState(enum.IntEnum):
@@ -4610,9 +4609,7 @@ def parse(self, block: Block) -> None:
46104609
fail('Tab characters are illegal in the Clinic DSL.\n\t' + repr(line), line_number=block_start)
46114610
self.state(line)
46124611

4613-
self.next(self.state_terminal)
4614-
self.state(None)
4615-
4612+
self.do_post_block_processing_cleanup()
46164613
block.output.extend(self.clinic.language.render(self.clinic, block.signatures))
46174614

46184615
if self.preserve_output:
@@ -4621,10 +4618,7 @@ def parse(self, block: Block) -> None:
46214618
block.output = self.saved_output
46224619

46234620
@staticmethod
4624-
def valid_line(line: str | None) -> TypeGuard[str]:
4625-
if line is None:
4626-
return False
4627-
4621+
def valid_line(line: str) -> bool:
46284622
# ignore comment-only lines
46294623
if line.lstrip().startswith('#'):
46304624
return False
@@ -4650,7 +4644,7 @@ def next(
46504644
if line is not None:
46514645
self.state(line)
46524646

4653-
def state_dsl_start(self, line: str | None) -> None:
4647+
def state_dsl_start(self, line: str) -> None:
46544648
# self.block = self.ClinicOutputBlock(self)
46554649
if not self.valid_line(line):
46564650
return
@@ -4668,7 +4662,7 @@ def state_dsl_start(self, line: str | None) -> None:
46684662

46694663
self.next(self.state_modulename_name, line)
46704664

4671-
def state_modulename_name(self, line: str | None) -> None:
4665+
def state_modulename_name(self, line: str) -> None:
46724666
# looking for declaration, which establishes the leftmost column
46734667
# line should be
46744668
# modulename.fnname [as c_basename] [-> return annotation]
@@ -4857,7 +4851,7 @@ def state_modulename_name(self, line: str | None) -> None:
48574851
# separate boolean state variables.) The states are defined in the
48584852
# ParamState class.
48594853

4860-
def state_parameters_start(self, line: str | None) -> None:
4854+
def state_parameters_start(self, line: str) -> None:
48614855
if not self.valid_line(line):
48624856
return
48634857

@@ -4879,7 +4873,7 @@ def to_required(self) -> None:
48794873
for p in self.function.parameters.values():
48804874
p.group = -p.group
48814875

4882-
def state_parameter(self, line: str | None) -> None:
4876+
def state_parameter(self, line: str) -> None:
48834877
assert isinstance(self.function, Function)
48844878

48854879
if not self.valid_line(line):
@@ -5262,7 +5256,7 @@ def parse_slash(self, function: Function) -> None:
52625256
"positional-only parameters, which is unsupported.")
52635257
p.kind = inspect.Parameter.POSITIONAL_ONLY
52645258

5265-
def state_parameter_docstring_start(self, line: str | None) -> None:
5259+
def state_parameter_docstring_start(self, line: str) -> None:
52665260
assert self.indent.margin is not None, "self.margin.infer() has not yet been called to set the margin"
52675261
self.parameter_docstring_indent = len(self.indent.margin)
52685262
assert self.indent.depth == 3
@@ -5271,9 +5265,7 @@ def state_parameter_docstring_start(self, line: str | None) -> None:
52715265
# every line of the docstring must start with at least F spaces,
52725266
# where F > P.
52735267
# these F spaces will be stripped.
5274-
def state_parameter_docstring(self, line: str | None) -> None:
5275-
assert line is not None
5276-
5268+
def state_parameter_docstring(self, line: str) -> None:
52775269
stripped = line.strip()
52785270
if stripped.startswith('#'):
52795271
return
@@ -5301,9 +5293,8 @@ def state_parameter_docstring(self, line: str | None) -> None:
53015293
last_parameter.docstring = new_docstring
53025294

53035295
# the final stanza of the DSL is the docstring.
5304-
def state_function_docstring(self, line: str | None) -> None:
5296+
def state_function_docstring(self, line: str) -> None:
53055297
assert self.function is not None
5306-
assert line is not None
53075298

53085299
if self.group:
53095300
fail("Function " + self.function.name + " has a ] without a matching [.")
@@ -5572,12 +5563,10 @@ def add_parameter(text: str) -> None:
55725563

55735564
return docstring
55745565

5575-
def state_terminal(self, line: str | None) -> None:
5566+
def do_post_block_processing_cleanup(self) -> None:
55765567
"""
55775568
Called when processing the block is done.
55785569
"""
5579-
assert not line
5580-
55815570
if not self.function:
55825571
return
55835572

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.