@@ -109,7 +109,7 @@ class _TextAccumulator(NamedTuple):
109
109
110
110
def _text_accumulator () -> _TextAccumulator :
111
111
text : list [str ] = []
112
- def output ():
112
+ def output () -> str :
113
113
s = '' .join (text )
114
114
text .clear ()
115
115
return s
@@ -433,10 +433,10 @@ class FormatCounterFormatter(string.Formatter):
433
433
the counts dict would now look like
434
434
{'a': 2, 'b': 1, 'c': 1}
435
435
"""
436
- def __init__ (self ):
437
- self .counts = collections .Counter ()
436
+ def __init__ (self ) -> None :
437
+ self .counts = collections .Counter [ str ] ()
438
438
439
- def get_value (self , key , args , kwargs ):
439
+ def get_value (self , key : str , args , kwargs ) -> str : # type: ignore[override]
440
440
self .counts [key ] += 1
441
441
return ''
442
442
@@ -447,18 +447,25 @@ class Language(metaclass=abc.ABCMeta):
447
447
stop_line = ""
448
448
checksum_line = ""
449
449
450
- def __init__ (self , filename ) :
450
+ def __init__ (self , filename : str ) -> None :
451
451
pass
452
452
453
453
@abc .abstractmethod
454
- def render (self , clinic , signatures ):
454
+ def render (
455
+ self ,
456
+ clinic : Clinic | None ,
457
+ signatures : Iterable [Module | Class | Function ]
458
+ ) -> str :
455
459
pass
456
460
457
- def parse_line (self , line ) :
461
+ def parse_line (self , line : str ) -> None :
458
462
pass
459
463
460
- def validate (self ):
461
- def assert_only_one (attr , * additional_fields ):
464
+ def validate (self ) -> None :
465
+ def assert_only_one (
466
+ attr : str ,
467
+ * additional_fields : str
468
+ ) -> None :
462
469
"""
463
470
Ensures that the string found at getattr(self, attr)
464
471
contains exactly one formatter replacement string for
@@ -485,10 +492,10 @@ def assert_only_one(attr, *additional_fields):
485
492
"""
486
493
fields = ['dsl_name' ]
487
494
fields .extend (additional_fields )
488
- line = getattr (self , attr )
495
+ line : str = getattr (self , attr )
489
496
fcf = FormatCounterFormatter ()
490
497
fcf .format (line )
491
- def local_fail (should_be_there_but_isnt ) :
498
+ def local_fail (should_be_there_but_isnt : bool ) -> None :
492
499
if should_be_there_but_isnt :
493
500
fail ("{} {} must contain {{{}}} exactly once!" .format (
494
501
self .__class__ .__name__ , attr , name ))
@@ -749,10 +756,10 @@ class CLanguage(Language):
749
756
stop_line = "[{dsl_name} start generated code]*/"
750
757
checksum_line = "/*[{dsl_name} end generated code: {arguments}]*/"
751
758
752
- def __init__ (self , filename ) :
759
+ def __init__ (self , filename : str ) -> None :
753
760
super ().__init__ (filename )
754
761
self .cpp = cpp .Monitor (filename )
755
- self .cpp .fail = fail
762
+ self .cpp .fail = fail # type: ignore[method-assign]
756
763
757
764
def parse_line (self , line : str ) -> None :
758
765
self .cpp .writeline (line )
@@ -935,6 +942,7 @@ def parser_body(
935
942
add (field )
936
943
return linear_format (output (), parser_declarations = declarations )
937
944
945
+ parsearg : str | None
938
946
if not parameters :
939
947
parser_code : list [str ] | None
940
948
if not requires_defining_class :
@@ -1880,7 +1888,12 @@ class BlockPrinter:
1880
1888
language : Language
1881
1889
f : io .StringIO = dc .field (default_factory = io .StringIO )
1882
1890
1883
- def print_block (self , block , * , core_includes = False ):
1891
+ def print_block (
1892
+ self ,
1893
+ block : Block ,
1894
+ * ,
1895
+ core_includes : bool = False
1896
+ ) -> None :
1884
1897
input = block .input
1885
1898
output = block .output
1886
1899
dsl_name = block .dsl_name
@@ -1931,7 +1944,7 @@ def print_block(self, block, *, core_includes=False):
1931
1944
write (self .language .checksum_line .format (dsl_name = dsl_name , arguments = arguments ))
1932
1945
write ("\n " )
1933
1946
1934
- def write (self , text ) :
1947
+ def write (self , text : str ) -> None :
1935
1948
self .f .write (text )
1936
1949
1937
1950
@@ -2755,7 +2768,7 @@ class CConverter(metaclass=CConverterAutoRegister):
2755
2768
# If not None, should be a string representing a pointer to a
2756
2769
# PyTypeObject (e.g. "&PyUnicode_Type").
2757
2770
# Only used by the 'O!' format unit (and the "object" converter).
2758
- subclass_of = None
2771
+ subclass_of : str | None = None
2759
2772
2760
2773
# Do we want an adjacent '_length' variable for this variable?
2761
2774
# Only used by format units ending with '#'.
@@ -2948,7 +2961,7 @@ def simple_declaration(self, by_reference=False, *, in_parser=False):
2948
2961
prototype .append (name )
2949
2962
return "" .join (prototype )
2950
2963
2951
- def declaration (self , * , in_parser = False ):
2964
+ def declaration (self , * , in_parser = False ) -> str :
2952
2965
"""
2953
2966
The C statement to declare this variable.
2954
2967
"""
@@ -3006,7 +3019,7 @@ def pre_render(self):
3006
3019
"""
3007
3020
pass
3008
3021
3009
- def parse_arg (self , argname , displayname ):
3022
+ def parse_arg (self , argname : str , displayname : str ):
3010
3023
if self .format_unit == 'O&' :
3011
3024
return """
3012
3025
if (!{converter}({argname}, &{paramname})) {{{{
0 commit comments