8000 gh-104050: Annotate more Argument Clinic DSLParser state methods by erlend-aasland · Pull Request #106376 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-104050: Annotate more Argument Clinic DSLParser state methods #106376

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

Merged
Merged
Changes from 1 commit
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
Next Next commit
Annotate Argument Clinic DSLParser.state_parameter()
  • Loading branch information
erlend-aasland committed Jul 3, 2023
commit fa43e47dd8a5d35272cf6cbddeb279b995072b0a
18 changes: 12 additions & 6 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4764,14 +4764,16 @@ def to_required(self):
for p in self.function.parameters.values():
p.group = -p.group

def state_parameter(self, line):
if self.parameter_continuation:
line = self.parameter_continuation + ' ' + line.lstrip()
self.parameter_continuation = ''
def state_parameter(self, line: str | None) -> None:
assert isinstance(self.function, Function)

if not self.valid_line(line):
return

if self.parameter_continuation:
line = self.parameter_continuation + ' ' + line.lstrip()
self.parameter_continuation = ''

assert self.indent.depth == 2
indent = self.indent.infer(line)
if indent == -1:
Expand Down Expand Up @@ -4821,6 +4823,7 @@ def state_parameter(self, line):
fields[0] = name
line = ' '.join(fields)

default: str | None
base, equals, default = line.rpartition('=')
if not equals:
base = default
Expand Down Expand Up @@ -4865,6 +4868,7 @@ def state_parameter(self, line):
if not default:
if self.parameter_state == self.ps_optional:
fail("Can't have a parameter without a default (" + repr(parameter_name) + ")\nafter a parameter with a default!")
value: Sentinels | Null
if is_vararg:
value = NULL
kwargs.setdefault('c_default', "NULL")
Expand Down Expand Up @@ -4929,6 +4933,7 @@ def bad_node(self, node):

expr = module.body[0].value
# mild hack: explicitly support NULL as a default value
c_default: str | None
if isinstance(expr, ast.Name) and expr.id == 'NULL':
value = NULL
py_default = '<unrepresentable>'
Expand All @@ -4945,7 +4950,7 @@ def bad_node(self, node):
value = unknown
elif isinstance(expr, ast.Attribute):
a = []
n = expr
n: ast.expr | ast.Attribute = expr
while isinstance(n, ast.Attribute):
a.append(n.attr)
n = n.value
Expand Down Expand Up @@ -4992,6 +4997,7 @@ def bad_node(self, node):
# but the parameter object gets the python name
converter = dict[name](c_name or parameter_name, parameter_name, self.function, value, **kwargs)

kind: inspect._ParameterKind
if is_vararg:
kind = inspect.Parameter.VAR_POSITIONAL
elif self.keyword_only:
Expand Down Expand Up @@ -5103,7 +5109,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: str) -> None:
def state_parameter_docstring_start(self, line: str | None) -> None:
self.parameter_docstring_indent = len(self.indent.margin)
assert self.indent.depth == 3
return self.next(self.state_parameter_docstring, line)
Expand Down
0