@@ -2205,7 +2205,7 @@ def print_block(
2205
2205
* ,
2206
2206
core_includes : bool = False ,
2207
2207
limited_capi : bool ,
2208
- header_includes : dict [str , str ],
2208
+ header_includes : dict [str , tuple [ str , str ] ],
2209
2209
) -> None :
2210
2210
input = block .input
2211
2211
output = block .output
@@ -2238,14 +2238,13 @@ def print_block(
2238
2238
# Emit optional "#include" directives for C headers
2239
2239
output += '\n '
2240
2240
2241
- def sort_key (item ) :
2241
+ def sort_key (item : tuple [ str , tuple [ str , str ]]) -> tuple [ str , str ] :
2242
2242
include , reason_condition = item
2243
2243
reason , condition = reason_condition
2244
2244
# '#if' is before 'NO_CONDITION'
2245
2245
return (condition or 'NO_CONDITION' , include )
2246
2246
2247
- current_condition = None
2248
-
2247
+ current_condition = ''
2249
2248
for include , reason_condition in sorted (header_includes .items (), key = sort_key ):
2250
2249
reason , condition = reason_condition
2251
2250
if condition != current_condition :
@@ -2477,7 +2476,7 @@ def __init__(
2477
2476
self .functions : list [Function ] = []
2478
2477
# dict: include name => reason
2479
2478
# Example: 'pycore_long.h' => '_PyLong_UnsignedShort_Converter()'
2480
- self .includes : dict [str , str ] = {}
2479
+ self .includes : dict [str , tuple [ str , str ] ] = {}
2481
2480
2482
2481
self .line_prefix = self .line_suffix = ''
2483
2482
@@ -2551,7 +2550,7 @@ def add_include(self, name: str, reason: str, condition: str | None = None) -> N
2551
2550
# no need to list all of them.
2552
2551
return
2553
2552
2554
- self .includes [name ] = (reason , condition )
2553
+ self .includes [name ] = (reason , condition or '' )
2555
2554
2556
2555
def add_destination (
2557
2556
self ,
0 commit comments