mirror of
https://github.com/python/cpython.git
synced 2024-12-11 18:53:56 +08:00
gh-104050: Add basic typing to CConverter in clinic.py (#104538)
This commit is contained in:
parent
cca90b6906
commit
505e2954a9
@ -2669,15 +2669,15 @@ class CConverter(metaclass=CConverterAutoRegister):
|
|||||||
# keep in sync with self_converter.__init__!
|
# keep in sync with self_converter.__init__!
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
# Positional args:
|
# Positional args:
|
||||||
name,
|
name: str,
|
||||||
py_name,
|
py_name: str,
|
||||||
function,
|
function,
|
||||||
default=unspecified,
|
default=unspecified,
|
||||||
*, # Keyword only args:
|
*, # Keyword only args:
|
||||||
c_default=None,
|
c_default: str | None = None,
|
||||||
py_default=None,
|
py_default: str | None = None,
|
||||||
annotation=unspecified,
|
annotation: str | Unspecified = unspecified,
|
||||||
unused=False,
|
unused: bool = False,
|
||||||
**kwargs
|
**kwargs
|
||||||
):
|
):
|
||||||
self.name = ensure_legal_c_identifier(name)
|
self.name = ensure_legal_c_identifier(name)
|
||||||
@ -2713,10 +2713,10 @@ class CConverter(metaclass=CConverterAutoRegister):
|
|||||||
def converter_init(self):
|
def converter_init(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def is_optional(self):
|
def is_optional(self) -> bool:
|
||||||
return (self.default is not unspecified)
|
return (self.default is not unspecified)
|
||||||
|
|
||||||
def _render_self(self, parameter, data):
|
def _render_self(self, parameter: str, data: CRenderData) -> None:
|
||||||
self.parameter = parameter
|
self.parameter = parameter
|
||||||
name = self.parser_name
|
name = self.parser_name
|
||||||
|
|
||||||
@ -2776,7 +2776,7 @@ class CConverter(metaclass=CConverterAutoRegister):
|
|||||||
if cleanup:
|
if cleanup:
|
||||||
data.cleanup.append('/* Cleanup for ' + name + ' */\n' + cleanup.rstrip() + "\n")
|
data.cleanup.append('/* Cleanup for ' + name + ' */\n' + cleanup.rstrip() + "\n")
|
||||||
|
|
||||||
def render(self, parameter, data):
|
def render(self, parameter: str, data: CRenderData) -> None:
|
||||||
"""
|
"""
|
||||||
parameter is a clinic.Parameter instance.
|
parameter is a clinic.Parameter instance.
|
||||||
data is a CRenderData instance.
|
data is a CRenderData instance.
|
||||||
@ -2852,7 +2852,7 @@ class CConverter(metaclass=CConverterAutoRegister):
|
|||||||
declaration.append(';')
|
declaration.append(';')
|
||||||
return "".join(declaration)
|
return "".join(declaration)
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self) -> str:
|
||||||
"""
|
"""
|
||||||
The C statements required to set up this variable before parsing.
|
The C statements required to set up this variable before parsing.
|
||||||
Returns a string containing this code indented at column 0.
|
Returns a string containing this code indented at column 0.
|
||||||
@ -2860,7 +2860,7 @@ class CConverter(metaclass=CConverterAutoRegister):
|
|||||||
"""
|
"""
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def modify(self):
|
def modify(self) -> str:
|
||||||
"""
|
"""
|
||||||
The C statements required to modify this variable after parsing.
|
The C statements required to modify this variable after parsing.
|
||||||
Returns a string containing this code indented at column 0.
|
Returns a string containing this code indented at column 0.
|
||||||
@ -2868,7 +2868,7 @@ class CConverter(metaclass=CConverterAutoRegister):
|
|||||||
"""
|
"""
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def post_parsing(self):
|
def post_parsing(self) -> str:
|
||||||
"""
|
"""
|
||||||
The C statements required to do some operations after the end of parsing but before cleaning up.
|
The C statements required to do some operations after the end of parsing but before cleaning up.
|
||||||
Return a string containing this code indented at column 0.
|
Return a string containing this code indented at column 0.
|
||||||
@ -2876,7 +2876,7 @@ class CConverter(metaclass=CConverterAutoRegister):
|
|||||||
"""
|
"""
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self) -> str:
|
||||||
"""
|
"""
|
||||||
The C statements required to clean up after this variable.
|
The C statements required to clean up after this variable.
|
||||||
Returns a string containing this code indented at column 0.
|
Returns a string containing this code indented at column 0.
|
||||||
@ -2929,7 +2929,7 @@ class CConverter(metaclass=CConverterAutoRegister):
|
|||||||
""".format(argname=argname, paramname=self.parser_name, cast=cast)
|
""".format(argname=argname, paramname=self.parser_name, cast=cast)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def set_template_dict(self, template_dict):
|
def set_template_dict(self, template_dict: dict[str, str]):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
Reference in New Issue
Block a user