|
25 | 25 | import sys |
26 | 26 | import textwrap |
27 | 27 | import traceback |
28 | | -import types |
29 | 28 |
|
30 | 29 | from collections.abc import Callable |
31 | | -from types import * |
| 30 | +from types import FunctionType, NoneType |
32 | 31 | from typing import Any, NamedTuple |
33 | 32 |
|
34 | 33 | # TODO: |
@@ -2669,15 +2668,15 @@ class CConverter(metaclass=CConverterAutoRegister): |
2669 | 2668 | # keep in sync with self_converter.__init__! |
2670 | 2669 | def __init__(self, |
2671 | 2670 | # Positional args: |
2672 | | - name, |
2673 | | - py_name, |
| 2671 | + name: str, |
| 2672 | + py_name: str, |
2674 | 2673 | function, |
2675 | 2674 | default=unspecified, |
2676 | 2675 | *, # Keyword only args: |
2677 | | - c_default=None, |
2678 | | - py_default=None, |
2679 | | - annotation=unspecified, |
2680 | | - unused=False, |
| 2676 | + c_default: str | None = None, |
| 2677 | + py_default: str | None = None, |
| 2678 | + annotation: str | Unspecified = unspecified, |
| 2679 | + unused: bool = False, |
2681 | 2680 | **kwargs |
2682 | 2681 | ): |
2683 | 2682 | self.name = ensure_legal_c_identifier(name) |
@@ -2713,10 +2712,10 @@ def __init__(self, |
2713 | 2712 | def converter_init(self): |
2714 | 2713 | pass |
2715 | 2714 |
|
2716 | | - def is_optional(self): |
| 2715 | + def is_optional(self) -> bool: |
2717 | 2716 | return (self.default is not unspecified) |
2718 | 2717 |
|
2719 | | - def _render_self(self, parameter, data): |
| 2718 | + def _render_self(self, parameter: str, data: CRenderData) -> None: |
2720 | 2719 | self.parameter = parameter |
2721 | 2720 | name = self.parser_name |
2722 | 2721 |
|
@@ -2776,7 +2775,7 @@ def _render_non_self(self, parameter, data): |
2776 | 2775 | if cleanup: |
2777 | 2776 | data.cleanup.append('/* Cleanup for ' + name + ' */\n' + cleanup.rstrip() + "\n") |
2778 | 2777 |
|
2779 | | - def render(self, parameter, data): |
| 2778 | + def render(self, parameter: str, data: CRenderData) -> None: |
2780 | 2779 | """ |
2781 | 2780 | parameter is a clinic.Parameter instance. |
2782 | 2781 | data is a CRenderData instance. |
@@ -2852,31 +2851,31 @@ def declaration(self, *, in_parser=False): |
2852 | 2851 | declaration.append(';') |
2853 | 2852 | return "".join(declaration) |
2854 | 2853 |
|
2855 | | - def initialize(self): |
| 2854 | + def initialize(self) -> str: |
2856 | 2855 | """ |
2857 | 2856 | The C statements required to set up this variable before parsing. |
2858 | 2857 | Returns a string containing this code indented at column 0. |
2859 | 2858 | If no initialization is necessary, returns an empty string. |
2860 | 2859 | """ |
2861 | 2860 | return "" |
2862 | 2861 |
|
2863 | | - def modify(self): |
| 2862 | + def modify(self) -> str: |
2864 | 2863 | """ |
2865 | 2864 | The C statements required to modify this variable after parsing. |
2866 | 2865 | Returns a string containing this code indented at column 0. |
2867 | 2866 | If no modification is necessary, returns an empty string. |
2868 | 2867 | """ |
2869 | 2868 | return "" |
2870 | 2869 |
|
2871 | | - def post_parsing(self): |
| 2870 | + def post_parsing(self) -> str: |
2872 | 2871 | """ |
2873 | 2872 | The C statements required to do some operations after the end of parsing but before cleaning up. |
2874 | 2873 | Return a string containing this code indented at column 0. |
2875 | 2874 | If no operation is necessary, return an empty string. |
2876 | 2875 | """ |
2877 | 2876 | return "" |
2878 | 2877 |
|
2879 | | - def cleanup(self): |
| 2878 | + def cleanup(self) -> str: |
2880 | 2879 | """ |
2881 | 2880 | The C statements required to clean up after this variable. |
2882 | 2881 | Returns a string containing this code indented at column 0. |
@@ -2929,7 +2928,7 @@ def parse_arg(self, argname, displayname): |
2929 | 2928 | """.format(argname=argname, paramname=self.parser_name, cast=cast) |
2930 | 2929 | return None |
2931 | 2930 |
|
2932 | | - def set_template_dict(self, template_dict): |
| 2931 | + def set_template_dict(self, template_dict: dict[str, str]): |
2933 | 2932 | pass |
2934 | 2933 |
|
2935 | 2934 | @property |
@@ -4037,7 +4036,7 @@ def eval_ast_expr(node, globals, *, filename='-'): |
4037 | 4036 |
|
4038 | 4037 | node = ast.Expression(node) |
4039 | 4038 | co = compile(node, filename, 'eval') |
4040 | | - fn = types.FunctionType(co, globals) |
| 4039 | + fn = FunctionType(co, globals) |
4041 | 4040 | return fn() |
4042 | 4041 |
|
4043 | 4042 |
|
|
0 commit comments