Skip to content

Commit

Permalink
pythongh-104050: Argument clinic: more misc typing coverage improveme…
Browse files Browse the repository at this point in the history
…nts (python#107210)
  • Loading branch information
AlexWaygood committed Jul 25, 2023
1 parent dbfe738 commit d9e34db
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,9 @@ class FormatCounterFormatter(string.Formatter):
def __init__(self) -> None:
self.counts = collections.Counter[str]()

def get_value(self, key: str, args, kwargs) -> str: # type: ignore[override]
def get_value(
self, key: str, args: object, kwargs: object # type: ignore[override]
) -> Literal['']:
self.counts[key] += 1
return ''

Expand Down Expand Up @@ -2797,7 +2799,7 @@ class CConverter(metaclass=CConverterAutoRegister):
# This lets the self_converter overrule the user-settable
# name, *just* for the text signature.
# Only set by self_converter.
signature_name = None
signature_name: str | None = None

# keep in sync with self_converter.__init__!
def __init__(self,
Expand All @@ -2811,8 +2813,8 @@ def __init__(self,
py_default: str | None = None,
annotation: str | Literal[Sentinels.unspecified] = unspecified,
unused: bool = False,
**kwargs
):
**kwargs: Any
) -> None:
self.name = ensure_legal_c_identifier(name)
self.py_name = py_name
self.unused = unused
Expand Down Expand Up @@ -2849,7 +2851,7 @@ def __init__(self,
self.converter_init(**kwargs)
self.function = function

def converter_init(self):
def converter_init(self) -> None:
pass

def is_optional(self) -> bool:
Expand Down Expand Up @@ -3032,7 +3034,7 @@ def cleanup(self) -> str:
"""
return ""

def pre_render(self):
def pre_render(self) -> None:
"""
A second initialization function, like converter_init,
called just before rendering.
Expand Down Expand Up @@ -3169,7 +3171,7 @@ class defining_class_converter(CConverter):
format_unit = ''
show_in_signature = False

def converter_init(self, *, type=None) -> None:
def converter_init(self, *, type: str | None = None) -> None:
self.specified_type = type

def render(self, parameter, data) -> None:
Expand Down Expand Up @@ -3321,7 +3323,9 @@ class int_converter(CConverter):
format_unit = 'i'
c_ignored_default = "0"

def converter_init(self, *, accept: TypeSet = {int}, type=None) -> None:
def converter_init(
self, *, accept: TypeSet = {int}, type: str | None = None
) -> None:
if accept == {str}:
self.format_unit = 'C'
elif accept != {int}:
Expand Down Expand Up @@ -3982,14 +3986,15 @@ class self_converter(CConverter):
A special-case converter:
this is the default converter used for "self".
"""
type = None
type: str | None = None
format_unit = ''

def converter_init(self, *, type: str | None = None) -> None:
self.specified_type = type

def pre_render(self):
def pre_render(self) -> None:
f = self.function
assert isinstance(f, Function)
default_type, default_name = correct_name_for_self(f)
self.signature_name = default_name
self.type = self.specified_type or self.type or default_type
Expand Down Expand Up @@ -4038,7 +4043,9 @@ def pre_render(self):
# in the impl call.

@property
def parser_type(self):
def parser_type(self) -> str:
assert self.type is not None
assert isinstance(self.function, Function)
return required_type_for_self_for_parser(self.function) or self.type

def render(self, parameter, data):
Expand Down

0 comments on commit d9e34db

Please sign in to comment.