@@ -236,14 +236,14 @@ async def solve_async(
236
236
237
237
"""
238
238
status = Status .UNKNOWN
239
- solution = None
240
239
statistics : Dict [str , Any ] = {}
241
240
242
241
multiple_solutions = (
243
242
all_solutions or intermediate_solutions or nr_solutions is not None
244
243
)
245
- if multiple_solutions :
246
- solution = []
244
+ solution : Union [Optional [Any ], List [Any ]] = (
245
+ [] if multiple_solutions else None
246
+ )
247
247
248
248
async for result in self .solutions (
249
249
time_limit = time_limit ,
@@ -261,7 +261,7 @@ async def solve_async(
261
261
statistics .update (result .statistics )
262
262
if result .solution is not None :
263
263
if multiple_solutions :
264
- assert solution is not None
264
+ assert isinstance ( solution , list )
265
265
solution .append (result .solution )
266
266
else :
267
267
solution = result .solution
@@ -302,12 +302,12 @@ async def diverse_solutions(
302
302
"mzn-analyse executable could not be located"
303
303
)
304
304
305
- try :
306
- # Create a temporary file in which the diversity model (generated by mzn-analyse) is placed
307
- div_file = tempfile .NamedTemporaryFile (
308
- prefix = "mzn_div" , suffix = ".mzn" , delete = False
309
- )
305
+ # Create a temporary file in which the diversity model (generated by mzn-analyse) is placed
306
+ div_file = tempfile .NamedTemporaryFile (
307
+ prefix = "mzn_div" , suffix = ".mzn" , delete = False
308
+ )
310
309
310
+ try :
311
311
# Extract the diversity annotations.
312
312
with self .files () as files :
313
313
div_anns = mzn_analyse .run (
@@ -610,12 +610,11 @@ async def solutions(
610
610
611
611
# Run the MiniZinc process
612
612
proc = await self ._driver ._create_process (cmd , solver = solver )
613
- try :
614
- assert isinstance (proc .stderr , asyncio .StreamReader )
615
- assert isinstance (proc .stdout , asyncio .StreamReader )
616
-
617
- read_stderr = asyncio .create_task (_read_all (proc .stderr ))
613
+ assert isinstance (proc .stderr , asyncio .StreamReader )
614
+ assert isinstance (proc .stdout , asyncio .StreamReader )
615
+ read_stderr = asyncio .create_task (_read_all (proc .stderr ))
618
616
617
+ try :
619
618
async for obj in decode_async_json_stream (
620
619
proc .stdout , cls = MZNJSONDecoder , enum_map = self ._enum_map
621
620
):
@@ -850,6 +849,7 @@ def analyse(self):
850
849
if obj ["type" ] == "interface" :
851
850
interface = obj
852
851
break
852
+ assert interface is not None
853
853
old_method = self ._method_cache
854
854
self ._method_cache = Method .from_string (interface ["method" ])
855
855
self ._input_cache = {}
@@ -1033,6 +1033,7 @@ def _parse_stream_obj(self, obj, statistics):
1033
1033
if "_checker" in statistics :
1034
1034
tmp ["_checker" ] = statistics .pop ("_checker" )
1035
1035
1036
+ assert self .output_type is not None
1036
1037
solution = self .output_type (** tmp )
1037
1038
statistics ["time" ] = timedelta (milliseconds = obj ["time" ])
1038
1039
elif obj ["type" ] == "time" :
0 commit comments