Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

gh-104050: Add more type hints to Argument Clinic DSLParser()#106343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletionsTools/clinic/clinic.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,15 @@

from collections.abc import Callable
from types import FunctionType, NoneType
from typing import Any, Final, NamedTuple, NoReturn, Literal, overload
from typing import (
Any,
Final,
Literal,
NamedTuple,
NoReturn,
TypeGuard,
overload,
)

# TODO:
#
Expand DownExpand Up@@ -4471,17 +4479,20 @@ def parse(self, block: Block) -> None:
block.output = self.saved_output

@staticmethod
def ignore_line(line):
def valid_line(line: str | None) -> TypeGuard[str]:
if line is None:
return False

# ignore comment-only lines
if line.lstrip().startswith('#'):
returnTrue
returnFalse

# Ignore empty lines too
# (but not in docstring sections!)
if not line.strip():
returnTrue
returnFalse

returnFalse
returnTrue

@staticmethod
def calculate_indent(line: str) -> int:
Expand All@@ -4497,9 +4508,9 @@ def next(
if line is not None:
self.state(line)

def state_dsl_start(self, line):
def state_dsl_start(self, line: str | None) -> None:
# self.block = self.ClinicOutputBlock(self)
if self.ignore_line(line):
ifnotself.valid_line(line):
return

# is it a directive?
Expand DownExpand Up@@ -4716,8 +4727,8 @@ def state_modulename_name(self, line):
ps_start, ps_left_square_before, ps_group_before, ps_required, \
ps_optional, ps_group_after, ps_right_square_after = range(7)

def state_parameters_start(self, line):
if self.ignore_line(line):
def state_parameters_start(self, line: str) -> None:
ifnotself.valid_line(line):
return

# if this line is not indented, we have no parameters
Expand All@@ -4742,7 +4753,7 @@ def state_parameter(self, line):
line = self.parameter_continuation + ' ' + line.lstrip()
self.parameter_continuation = ''

if self.ignore_line(line):
ifnotself.valid_line(line):
return

assert self.indent.depth == 2
Expand DownExpand Up@@ -5075,7 +5086,7 @@ def parse_special_symbol(self, symbol):
fail("Function " + self.function.name + " mixes keyword-only and positional-only parameters, which is unsupported.")
p.kind = inspect.Parameter.POSITIONAL_ONLY

def state_parameter_docstring_start(self, line):
def state_parameter_docstring_start(self, line: str) -> None:
self.parameter_docstring_indent = len(self.indent.margin)
assert self.indent.depth == 3
return self.next(self.state_parameter_docstring, line)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp