@@ -19,6 +19,9 @@ def __getitem__(self, item):
19
19
PyInterfaceType = InfinitelySubscriptable ()
20
20
PyStarExpr = InfinitelySubscriptable ()
21
21
22
+ # Special identifiers can go here
23
+ PY_EMPTY_STRUCT = None
24
+
22
25
23
26
class BindType (Enum ):
24
27
PARAMLESS_FUNC_LIT = 0
@@ -288,6 +291,63 @@ def go_copy(s) -> PyInterfaceType[tmp]:
288
291
tmp = append (tmp , * ('*' @s ))
289
292
return
290
293
294
+ # Set methods
295
+ @Bindable .add (r"(.*)\.add" , bind_type = BindType .STMT )
296
+ def go_add (s , elt ):
297
+ s [elt ] = PY_EMPTY_STRUCT
298
+
299
+ s1 = TypeVar ("s1" )
300
+ @Bindable .add (r"(.*)\.union" , bind_type = BindType .FUNC_LIT )
301
+ def go_union (s1 : set , s2 : set ) -> PyInterfaceType [s1 ]:
302
+ union = set ()
303
+ for elt in s1 :
304
+ union .add (elt )
305
+ for elt in s2 :
306
+ union .add (elt )
307
+ return union
308
+
309
+ @Bindable .add (r"(.*)\.intersection" , bind_type = BindType .FUNC_LIT )
310
+ def go_intersection (s1 : set , s2 : set ) -> PyInterfaceType [s1 ]:
311
+ intersection = set ()
312
+ for elt in s1 :
313
+ if elt in s2 :
314
+ intersection .add (elt )
315
+ return intersection
316
+
317
+ @Bindable .add (r"(.*)\.difference" , bind_type = BindType .FUNC_LIT )
318
+ def go_difference (s1 : set , s2 : set ) -> PyInterfaceType [s1 ]:
319
+ difference = set ()
320
+ for elt in s1 :
321
+ if elt not in s2 :
322
+ difference .add (elt )
323
+ return difference
324
+
325
+ @Bindable .add (r"(.*)\.symmetric_difference" , bind_type = BindType .FUNC_LIT )
326
+ def go_symmetric_intersection (s1 : set , s2 : set ) -> PyInterfaceType [s1 ]:
327
+ symmetric_intersection = set ()
328
+ for elt in s1 :
329
+ if elt not in s2 :
330
+ symmetric_intersection .add (elt )
331
+ for elt in s2 :
332
+ if elt not in s1 :
333
+ symmetric_intersection .add (elt )
334
+ return symmetric_intersection
335
+
336
+ @Bindable .add (r"(.*)\.issubset" , bind_type = BindType .FUNC_LIT )
337
+ def go_issubset (s1 : set , s2 : set ) -> bool :
338
+ for elt in s1 :
339
+ if elt not in s2 :
340
+ return False
341
+ return True
342
+
343
+ @Bindable .add (r"(.*)\.issuperset" , bind_type = BindType .FUNC_LIT )
344
+ def go_is_subset (s1 : set , s2 : set ) -> bool :
345
+ for elt in s2 :
346
+ if elt not in s1 :
347
+ return False
348
+ return True
349
+
350
+
291
351
# Dict methods
292
352
293
353
@Bindable .add (r"(.*)\.keys" , bind_type = BindType .EXPR )
0 commit comments