@@ -255,14 +255,20 @@ def visit_sequence_pattern(self, o: SequencePattern) -> PatternType:
255
255
state : (
256
256
# Start in the state where we not encountered an unpack.
257
257
# a list of all the possible types that could match the sequence. If it's a tuple, then store one for each index
258
- tuple [Literal ["NO_UNPACK" ], list [list [Type ]]] |
258
+ tuple [Literal ["NO_UNPACK" ], list [list [Type ]]]
259
+ |
259
260
# If we encounter a single tuple with an unpack, store the type, the unpack index, and the index in the union type
260
- tuple [Literal ["UNPACK" ], TupleType , int , int ] |
261
+ tuple [Literal ["UNPACK" ], TupleType , int , int ]
262
+ |
261
263
# If we have encountered a tuple with an unpack plus any other types, then store a list of them. For any tuples
262
264
# without unpacks, store them as a list of their items.
263
265
tuple [Literal ["MULTI_UNPACK" ], list [list [Type ]]]
264
- ) = ("NO_UNPACK" , [])
265
- for i , t in enumerate (current_type .items ) if isinstance (current_type , UnionType ) else ((0 , current_type ),):
266
+ ) = ("NO_UNPACK" , [])
267
+ for i , t in (
268
+ enumerate (current_type .items )
269
+ if isinstance (current_type , UnionType )
270
+ else ((0 , current_type ),)
271
+ ):
266
272
t = get_proper_type (t )
267
273
n_patterns = len (o .patterns )
268
274
if isinstance (t , TupleType ):
@@ -301,8 +307,11 @@ def visit_sequence_pattern(self, o: SequencePattern) -> PatternType:
301
307
# if we previously encountered an unpack, then change the state.
302
308
if state [0 ] == "UNPACK" :
303
309
# if we already unpacked something, change this
304
- state = ("MULTI_UNPACK" , [[self .chk .iterable_item_type (tuple_fallback (state [1 ]), o )] * n_patterns ])
305
- assert state [0 ] != "UNPACK" # for type checker
310
+ state = (
311
+ "MULTI_UNPACK" ,
312
+ [[self .chk .iterable_item_type (tuple_fallback (state [1 ]), o )] * n_patterns ],
313
+ )
314
+ assert state [0 ] != "UNPACK" # for type checker
306
315
state [1 ].append (inner_t )
307
316
if state [0 ] == "UNPACK" :
308
317
_ , update_tuple_type , unpack_index , union_index = state
@@ -318,7 +327,10 @@ def visit_sequence_pattern(self, o: SequencePattern) -> PatternType:
318
327
unpack_index = None
319
328
if not state [1 ]:
320
329
return self .early_non_match ()
321
- inner_types = [make_simplified_union (x ) for x in zip_longest (* state [1 ], fillvalue = UninhabitedType ())]
330
+ inner_types = [
331
+ make_simplified_union (x )
332
+ for x in zip_longest (* state [1 ], fillvalue = UninhabitedType ())
333
+ ]
322
334
323
335
#
324
336
# match inner patterns
0 commit comments