77
88import abc
99import ast
10+ import builtins as bltns
1011import collections
1112import contextlib
1213import copy
2627import traceback
2728import types
2829
30+ from collections .abc import Callable
2931from types import *
32+ from typing import Any , NamedTuple
3033
3134# TODO:
3235#
@@ -78,19 +81,26 @@ def __repr__(self):
7881
7982sig_end_marker = '--'
8083
84+ Appender = Callable [[str ], None ]
85+ Outputter = Callable [[None ], str ]
8186
82- _text_accumulator_nt = collections .namedtuple ("_text_accumulator" , "text append output" )
87+ class _TextAccumulator (NamedTuple ):
88+ text : list [str ]
89+ append : Appender
90+ output : Outputter
8391
8492def _text_accumulator ():
8593 text = []
8694 def output ():
8795 s = '' .join (text )
8896 text .clear ()
8997 return s
90- return _text_accumulator_nt (text , text .append , output )
98+ return _TextAccumulator (text , text .append , output )
9199
92100
93- text_accumulator_nt = collections .namedtuple ("text_accumulator" , "text append" )
101+ class TextAccumulator (NamedTuple ):
102+ text : list [str ]
103+ append : Appender
94104
95105def text_accumulator ():
96106 """
@@ -104,7 +114,7 @@ def text_accumulator():
104114 empties the accumulator.
105115 """
106116 text , append , output = _text_accumulator ()
107- return text_accumulator_nt (append , output )
117+ return TextAccumulator (append , output )
108118
109119
110120def warn_or_fail (fail = False , * args , filename = None , line_number = None ):
@@ -1925,8 +1935,10 @@ def dump(self):
19251935# maps strings to Language objects.
19261936# "languages" maps the name of the language ("C", "Python").
19271937# "extensions" maps the file extension ("c", "py").
1938+ LangDict = dict [str , Callable [[str ], Language ]]
1939+
19281940languages = { 'C' : CLanguage , 'Python' : PythonLanguage }
1929- extensions = { name : CLanguage for name in "c cc cpp cxx h hh hpp hxx" .split () }
1941+ extensions : LangDict = { name : CLanguage for name in "c cc cpp cxx h hh hpp hxx" .split () }
19301942extensions ['py' ] = PythonLanguage
19311943
19321944
@@ -2558,15 +2570,15 @@ class CConverter(metaclass=CConverterAutoRegister):
25582570 """
25592571
25602572 # The C name to use for this variable.
2561- name = None
2573+ name : str | None = None
25622574
25632575 # The Python name to use for this variable.
2564- py_name = None
2576+ py_name : str | None = None
25652577
25662578 # The C type to use for this variable.
25672579 # 'type' should be a Python string specifying the type, e.g. "int".
25682580 # If this is a pointer type, the type string should end with ' *'.
2569- type = None
2581+ type : str | None = None
25702582
25712583 # The Python default value for this parameter, as a Python value.
25722584 # Or the magic value "unspecified" if there is no default.
@@ -2577,15 +2589,15 @@ class CConverter(metaclass=CConverterAutoRegister):
25772589
25782590 # If not None, default must be isinstance() of this type.
25792591 # (You can also specify a tuple of types.)
2580- default_type = None
2592+ default_type : bltns . type [ Any ] | tuple [ bltns . type [ Any ], ...] | None = None
25812593
25822594 # "default" converted into a C value, as a string.
25832595 # Or None if there is no default.
2584- c_default = None
2596+ c_default : str | None = None
25852597
25862598 # "default" converted into a Python value, as a string.
25872599 # Or None if there is no default.
2588- py_default = None
2600+ py_default : str | None = None
25892601
25902602 # The default value used to initialize the C variable when
25912603 # there is no default, but not specifying a default may
@@ -2597,14 +2609,14 @@ class CConverter(metaclass=CConverterAutoRegister):
25972609 #
25982610 # This value is specified as a string.
25992611 # Every non-abstract subclass should supply a valid value.
2600- c_ignored_default = 'NULL'
2612+ c_ignored_default : str = 'NULL'
26012613
26022614 # If true, wrap with Py_UNUSED.
26032615 unused = False
26042616
26052617 # The C converter *function* to be used, if any.
26062618 # (If this is not None, format_unit must be 'O&'.)
2607- converter = None
2619+ converter : str | None = None
26082620
26092621 # Should Argument Clinic add a '&' before the name of
26102622 # the variable when passing it into the _impl function?
@@ -3432,7 +3444,7 @@ class robuffer: pass
34323444def str_converter_key (types , encoding , zeroes ):
34333445 return (frozenset (types ), bool (encoding ), bool (zeroes ))
34343446
3435- str_converter_argument_map = {}
3447+ str_converter_argument_map : dict [ str , str ] = {}
34363448
34373449class str_converter (CConverter ):
34383450 type = 'const char *'
0 commit comments