Skip to content

Commit

Permalink
address review, style: use f-strings, code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Oct 28, 2024
1 parent 1dc2756 commit 00a356b
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions Tools/clinic/libclinic/parse_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,7 @@ def parse_pos_only(self) -> None:
argname_fmt = 'PyTuple_GET_ITEM(args, %d)'

if self.vararg != NO_VARARG:
if self.max_pos == 0:
self.declarations = "Py_ssize_t nvararg = %s;" % nargs
else:
self.declarations = "Py_ssize_t nvararg = Py_MAX(%s - %d, 0);" % (nargs, self.max_pos)
self.declarations = f"Py_ssize_t nvararg = {nargs} - {self.max_pos};"
else:
self.declarations = ""

Expand Down Expand Up @@ -525,17 +522,13 @@ def parse_pos_only(self) -> None:
use_parser_code = True
for i, p in enumerate(self.parameters):
if p.is_vararg():
var = p.converter.parser_name
if self.fastcall:
parser_code.append(libclinic.normalize_snippet("""
%s = args + %s;
""" % (
p.converter.parser_name,
self.vararg
), indent=4))
code = f"{var} = args + {self.vararg};"
else:
parser_code.append(libclinic.normalize_snippet("""
%s = _PyTuple_CAST(args)->ob_item;
""" % p.converter.parser_name, indent=4))
code = f"{var} = _PyTuple_CAST(args)->ob_item;"
formatted_code = libclinic.normalize_snippet(code, indent=4)
parser_code.append(formatted_code)
continue

displayname = p.get_displayname(i+1)
Expand Down

0 comments on commit 00a356b

Please sign in to comment.