Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-104683: Argument clinic: remove some unnecessary uses of self.next() in the DSLParser #107635

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
18 changes: 6 additions & 12 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4666,9 +4666,9 @@ def state_dsl_start(self, line: str) -> None:
fail(str(e))
return

self.next(self.state_modulename_name, line)
self.parse_modulename_name(line)

def state_modulename_name(self, line: str) -> None:
def parse_modulename_name(self, line: str) -> None:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed this function to distinguish it from the state_foo functions, all of which must only ever be called indirectly via self.next()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of parse_function_declaration?

Suggested change
def parse_modulename_name(self, line: str) -> None:
def parse_function_declaration(self, line: str) -> None:

# looking for declaration, which establishes the leftmost column
# line should be
# modulename.fnname [as c_basename] [-> return annotation]
Expand All @@ -4685,9 +4685,6 @@ def state_modulename_name(self, line: str) -> None:
# this line is permitted to start with whitespace.
# we'll call this number of spaces F (for "function").

if not self.valid_line(line):
return
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved

self.indent.infer(line)

# are we cloning?
Expand Down Expand Up @@ -4896,7 +4893,10 @@ def state_parameter(self, line: str) -> None:

if indent == 1:
# we indented, must be to new parameter docstring column
return self.next(self.state_parameter_docstring_start, line)
assert self.indent.margin is not None
self.parameter_docstring_indent = len(self.indent.margin)
assert self.indent.depth == 3
return self.next(self.state_parameter_docstring, line)

line = line.rstrip()
if line.endswith('\\'):
Expand Down Expand Up @@ -5278,12 +5278,6 @@ def parse_slash(self, function: Function) -> None:
"positional-only parameters, which is unsupported.")
p.kind = inspect.Parameter.POSITIONAL_ONLY

def state_parameter_docstring_start(self, line: str) -> None:
assert self.indent.margin is not None, "self.margin.infer() has not yet been called to set the margin"
self.parameter_docstring_indent = len(self.indent.margin)
assert self.indent.depth == 3
return self.next(self.state_parameter_docstring, line)

def docstring_append(self, obj: Function | Parameter, line: str) -> None:
"""Add a rstripped line to the current docstring."""
matches = re.finditer(r'[^\x00-\x7F]', line)
Expand Down
Loading