@@ -2115,9 +2115,10 @@ class BlockPrinter:
21152115 def print_block (
21162116 self ,
21172117 block : Block ,
2118- clinic : Clinic ,
21192118 * ,
2120- core_includes : bool = False
2119+ core_includes : bool = False ,
2120+ # needed if core_includes is true
2121+ clinic : Clinic | None = None ,
21212122 ) -> None :
21222123 input = block .input
21232124 output = block .output
@@ -2146,7 +2147,7 @@ def print_block(
21462147 write ("\n " )
21472148
21482149 output = ''
2149- if core_includes :
2150+ if core_includes and clinic :
21502151 output += textwrap .dedent ("""
21512152 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
21522153 # include "pycore_gc.h" // PyGC_Head
@@ -2303,7 +2304,7 @@ def __init__(self, clinic: Clinic) -> None: ...
23032304 def parse (self , block : Block ) -> None : ...
23042305
23052306
2306- clinic = None
2307+ clinic : Clinic | None = None
23072308class Clinic :
23082309
23092310 presets_text = """
@@ -2430,7 +2431,7 @@ def __init__(
24302431 global clinic
24312432 clinic = self
24322433
2433- def add_include (self , name : str , reason : str ):
2434+ def add_include (self , name : str , reason : str ) -> None :
24342435 if name in self .includes :
24352436 return
24362437 self .includes [name ] = reason
@@ -2470,7 +2471,7 @@ def parse(self, input: str) -> str:
24702471 self .parsers [dsl_name ] = parsers [dsl_name ](self )
24712472 parser = self .parsers [dsl_name ]
24722473 parser .parse (block )
2473- printer .print_block (block , clinic )
2474+ printer .print_block (block )
24742475
24752476 # these are destinations not buffers
24762477 for name , destination in self .destinations .items ():
@@ -2485,7 +2486,7 @@ def parse(self, input: str) -> str:
24852486 block .input = "dump " + name + "\n "
24862487 warn ("Destination buffer " + repr (name ) + " not empty at end of file, emptying." )
24872488 printer .write ("\n " )
2488- printer .print_block (block , clinic )
2489+ printer .print_block (block )
24892490 continue
24902491
24912492 if destination .type == 'file' :
@@ -2510,7 +2511,7 @@ def parse(self, input: str) -> str:
25102511
25112512 block .input = 'preserve\n '
25122513 printer_2 = BlockPrinter (self .language )
2513- printer_2 .print_block (block , clinic , core_includes = True )
2514+ printer_2 .print_block (block , core_includes = True , clinic = self )
25142515 write_file (destination .filename , printer_2 .f .getvalue ())
25152516 continue
25162517
@@ -3362,7 +3363,7 @@ def parser_name(self) -> str:
33623363 else :
33633364 return self .name
33643365
3365- def add_include (self , name , reason ) :
3366+ def add_include (self , name : str , reason : str ) -> None :
33663367 if self .include :
33673368 raise ValueError ("a converter only supports a single include" )
33683369 self .include = (name , reason )
@@ -5987,9 +5988,6 @@ def do_post_block_processing_cleanup(self, lineno: int) -> None:
59875988}
59885989
59895990
5990- clinic = None
5991-
5992-
59935991def create_cli () -> argparse .ArgumentParser :
59945992 cmdline = argparse .ArgumentParser (
59955993 prog = "clinic.py" ,
0 commit comments