[Python-checkins] gh-104050: Argument clinic: more misc typing coverage improvements (#107210)

AlexWaygood webhook-mailer at python.org
Tue Jul 25 04:49:11 EDT 2023


https://github.com/python/cpython/commit/d9e34db993ebc4340459ac5cb3a66c1b83451a66
commit: d9e34db993ebc4340459ac5cb3a66c1b83451a66
branch: main
author: Alex Waygood <Alex.Waygood at Gmail.com>
committer: AlexWaygood <Alex.Waygood at Gmail.com>
date: 2023-07-25T08:49:07Z
summary:

gh-104050: Argument clinic: more misc typing coverage improvements (#107210)

files:
M Tools/clinic/clinic.py

diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 9c18fec055f81..8c959ed4d0044 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -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 ''
 
@@ -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,
@@ -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
@@ -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:
@@ -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.
@@ -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:
@@ -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}:
@@ -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
@@ -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):



More information about the Python-checkins mailing list