Skip to content
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
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
  • Loading branch information
AlexWaygood and erlend-aasland authored May 20, 2023
commit 841c7f7ef93069983b73fbf891e6e4db9dec93ab
26 changes: 15 additions & 11 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def is_legal_py_identifier(s: str) -> bool:
def ensure_legal_c_identifier(s: str) -> str:
# for now, just complain if what we're given isn't legal
if not is_legal_c_identifier(s):
fail(f"Illegal C identifier: {s}")
fail("Illegal C identifier:", s)
# but if we picked a C keyword, pick something else
if s in c_keywords:
return s + "_value"
Expand Down Expand Up @@ -1487,8 +1487,7 @@ def render_function(self, clinic, f):

template_dict['c_basename'] = c_basename

methoddef_name = f"{c_basename.upper()}_METHODDEF"
template_dict['methoddef_name'] = methoddef_name
template_dict['methoddef_name'] = c_basename.upper() + "_METHODDEF"

template_dict['docstring'] = self.docstring_for_c_string(f)

Expand Down Expand Up @@ -1867,7 +1866,10 @@ def print_block(self, block, *, core_includes=False):
output += '\n'
write(output)

arguments=f"output={compute_checksum(output, 16)} input={compute_checksum(input, 16)}"
arguments="output={output}, input={input}".format(
output=compute_checksum(output, 16),
input=compute_checksum(input, 16)
)
write(self.language.checksum_line.format(dsl_name=dsl_name, arguments=arguments))
write("\n")

Expand Down Expand Up @@ -2537,7 +2539,7 @@ def get_displayname(self, i):
if i == 0:
return '"argument"'
if not self.is_positional_only():
return f'''"argument '{self.name}'"'''
return f'"argument {self.name!r}"'
else:
return f'"argument {i}"'

Expand Down Expand Up @@ -2723,7 +2725,8 @@ def __init__(self,
if isinstance(self.default_type, type):
types_str = self.default_type.__name__
else:
types_str = ', '.join(cls.__name__ for cls in self.default_type)
names = (cls.__name__ for cls in self.default_type)
types_str = ', '.join(names)
fail("{}: default value {!r} for field {} is not of type {}".format(
self.__class__.__name__, default, name, types_str))
self.default = default
Expand Down Expand Up @@ -4011,10 +4014,12 @@ def declare(self, data):
data.return_value = data.converter_retval

def err_occurred_if(self, expr, data):
data.return_conversion.append(f'if (({expr}) && PyErr_Occurred()) {{\n goto exit;\n}}\n')
line = f'if (({expr}) && PyErr_Occurred()) {{\n goto exit;\n}}\n'
data.return_conversion.append(line)

def err_occurred_if_null_pointer(self, variable, data):
data.return_conversion.append(f'if ({variable} == NULL) {{\n goto exit;\n}}\n')
line = f'if ({variable} == NULL) {{\n goto exit;\n}}\n'
data.return_conversion.append(line)

def render(self, function, data):
"""
Expand Down Expand Up @@ -4477,9 +4482,9 @@ def state_modulename_name(self, line):
c_basename = c_basename.strip() or None

if not is_legal_py_identifier(full_name):
fail(f"Illegal function name: {full_name}")
fail("Illegal function name:", full_name)
if c_basename and not is_legal_c_identifier(c_basename):
fail(f"Illegal C basename: {c_basename}")
fail("Illegal C basename:", c_basename)

return_converter = None
if returns:
Expand Down Expand Up @@ -4749,7 +4754,6 @@ def state_parameter(self, line):
default = default.strip()
bad = False
ast_input = f"x = {default}"
bad = False
try:
module = ast.parse(ast_input)

Expand Down