mirror of https://github.com/python/cpython
gh-104050: Argument Clinic: Increase CConverter typing coverage (#106932)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
42c6300d4f
commit
1d5a625eb0
|
@ -2698,10 +2698,10 @@ class CConverter(metaclass=CConverterAutoRegister):
|
|||
"""
|
||||
|
||||
# The C name to use for this variable.
|
||||
name: str | None = None
|
||||
name: str
|
||||
|
||||
# The Python name to use for this variable.
|
||||
py_name: str | None = None
|
||||
py_name: str
|
||||
|
||||
# The C type to use for this variable.
|
||||
# 'type' should be a Python string specifying the type, e.g. "int".
|
||||
|
@ -2864,7 +2864,11 @@ class CConverter(metaclass=CConverterAutoRegister):
|
|||
if self.length:
|
||||
data.impl_parameters.append("Py_ssize_t " + self.length_name())
|
||||
|
||||
def _render_non_self(self, parameter, data):
|
||||
def _render_non_self(
|
||||
self,
|
||||
parameter: Parameter,
|
||||
data: CRenderData
|
||||
) -> None:
|
||||
self.parameter = parameter
|
||||
name = self.name
|
||||
|
||||
|
@ -2917,31 +2921,30 @@ class CConverter(metaclass=CConverterAutoRegister):
|
|||
self._render_self(parameter, data)
|
||||
self._render_non_self(parameter, data)
|
||||
|
||||
def length_name(self):
|
||||
def length_name(self) -> str:
|
||||
"""Computes the name of the associated "length" variable."""
|
||||
if not self.length:
|
||||
return None
|
||||
assert self.length is not None
|
||||
return self.parser_name + "_length"
|
||||
|
||||
# Why is this one broken out separately?
|
||||
# For "positional-only" function parsing,
|
||||
# which generates a bunch of PyArg_ParseTuple calls.
|
||||
def parse_argument(self, list):
|
||||
def parse_argument(self, args: list[str]) -> None:
|
||||
assert not (self.converter and self.encoding)
|
||||
if self.format_unit == 'O&':
|
||||
assert self.converter
|
||||
list.append(self.converter)
|
||||
args.append(self.converter)
|
||||
|
||||
if self.encoding:
|
||||
list.append(c_repr(self.encoding))
|
||||
args.append(c_repr(self.encoding))
|
||||
elif self.subclass_of:
|
||||
list.append(self.subclass_of)
|
||||
args.append(self.subclass_of)
|
||||
|
||||
s = ("&" if self.parse_by_reference else "") + self.name
|
||||
list.append(s)
|
||||
args.append(s)
|
||||
|
||||
if self.length:
|
||||
list.append("&" + self.length_name())
|
||||
args.append("&" + self.length_name())
|
||||
|
||||
#
|
||||
# All the functions after here are intended as extension points.
|
||||
|
@ -3066,7 +3069,7 @@ class CConverter(metaclass=CConverterAutoRegister):
|
|||
pass
|
||||
|
||||
@property
|
||||
def parser_name(self):
|
||||
def parser_name(self) -> str:
|
||||
if self.name in CLINIC_PREFIXED_ARGS: # bpo-39741
|
||||
return CLINIC_PREFIX + self.name
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue