Coverage Report

Created: 2026-10-31 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Objects/clinic/setobject.c.h
Line
Count
Source
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
#include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
6
7
static PyObject *
8
set_repr_impl(PySetObject *so);
9
10
static PyObject *
11
set_repr(PyObject *so)
12
0
{
13
0
    PyObject *return_value = NULL;
14
15
0
    Py_BEGIN_CRITICAL_SECTION(so);
16
0
    return_value = set_repr_impl((PySetObject *)so);
17
0
    Py_END_CRITICAL_SECTION();
18
19
0
    return return_value;
20
0
}
21
22
PyDoc_STRVAR(set_pop__doc__,
23
"pop($self, /)\n"
24
"--\n"
25
"\n"
26
"Remove and return an arbitrary set element.\n"
27
"\n"
28
"Raises KeyError if the set is empty.");
29
30
#define SET_POP_METHODDEF    \
31
    {"pop", (PyCFunction)set_pop, METH_NOARGS, set_pop__doc__},
32
33
static PyObject *
34
set_pop_impl(PySetObject *so);
35
36
static PyObject *
37
set_pop(PyObject *so, PyObject *Py_UNUSED(ignored))
38
290
{
39
290
    PyObject *return_value = NULL;
40
41
290
    Py_BEGIN_CRITICAL_SECTION(so);
42
290
    return_value = set_pop_impl((PySetObject *)so);
43
290
    Py_END_CRITICAL_SECTION();
44
45
290
    return return_value;
46
290
}
47
48
PyDoc_STRVAR(set_update__doc__,
49
"update($self, /, *others)\n"
50
"--\n"
51
"\n"
52
"Update the set, adding elements from all others.");
53
54
#define SET_UPDATE_METHODDEF    \
55
    {"update", _PyCFunction_CAST(set_update), METH_FASTCALL, set_update__doc__},
56
57
static PyObject *
58
set_update_impl(PySetObject *so, PyObject * const *others,
59
                Py_ssize_t others_length);
60
61
static PyObject *
62
set_update(PyObject *so, PyObject *const *args, Py_ssize_t nargs)
63
245k
{
64
245k
    PyObject *return_value = NULL;
65
245k
    PyObject * const *others;
66
245k
    Py_ssize_t others_length;
67
68
245k
    others = args;
69
245k
    others_length = nargs;
70
245k
    return_value = set_update_impl((PySetObject *)so, others, others_length);
71
72
245k
    return return_value;
73
245k
}
74
75
PyDoc_STRVAR(set_copy__doc__,
76
"copy($self, /)\n"
77
"--\n"
78
"\n"
79
"Return a shallow copy of a set.");
80
81
#define SET_COPY_METHODDEF    \
82
    {"copy", (PyCFunction)set_copy, METH_NOARGS, set_copy__doc__},
83
84
static PyObject *
85
set_copy_impl(PySetObject *so);
86
87
static PyObject *
88
set_copy(PyObject *so, PyObject *Py_UNUSED(ignored))
89
886
{
90
886
    PyObject *return_value = NULL;
91
92
886
    Py_BEGIN_CRITICAL_SECTION(so);
93
886
    return_value = set_copy_impl((PySetObject *)so);
94
886
    Py_END_CRITICAL_SECTION();
95
96
886
    return return_value;
97
886
}
98
99
PyDoc_STRVAR(frozenset_copy__doc__,
100
"copy($self, /)\n"
101
"--\n"
102
"\n"
103
"Return a shallow copy of a set.");
104
105
#define FROZENSET_COPY_METHODDEF    \
106
    {"copy", (PyCFunction)frozenset_copy, METH_NOARGS, frozenset_copy__doc__},
107
108
static PyObject *
109
frozenset_copy_impl(PySetObject *so);
110
111
static PyObject *
112
frozenset_copy(PyObject *so, PyObject *Py_UNUSED(ignored))
113
0
{
114
0
    PyObject *return_value = NULL;
115
116
0
    Py_BEGIN_CRITICAL_SECTION(so);
117
0
    return_value = frozenset_copy_impl((PySetObject *)so);
118
0
    Py_END_CRITICAL_SECTION();
119
120
0
    return return_value;
121
0
}
122
123
PyDoc_STRVAR(set_clear__doc__,
124
"clear($self, /)\n"
125
"--\n"
126
"\n"
127
"Remove all elements from this set.");
128
129
#define SET_CLEAR_METHODDEF    \
130
    {"clear", (PyCFunction)set_clear, METH_NOARGS, set_clear__doc__},
131
132
static PyObject *
133
set_clear_impl(PySetObject *so);
134
135
static PyObject *
136
set_clear(PyObject *so, PyObject *Py_UNUSED(ignored))
137
68.3k
{
138
68.3k
    PyObject *return_value = NULL;
139
140
68.3k
    Py_BEGIN_CRITICAL_SECTION(so);
141
68.3k
    return_value = set_clear_impl((PySetObject *)so);
142
68.3k
    Py_END_CRITICAL_SECTION();
143
144
68.3k
    return return_value;
145
68.3k
}
146
147
PyDoc_STRVAR(set_union__doc__,
148
"union($self, /, *others)\n"
149
"--\n"
150
"\n"
151
"Return a new set with elements from the set and all others.");
152
153
#define SET_UNION_METHODDEF    \
154
    {"union", _PyCFunction_CAST(set_union), METH_FASTCALL, set_union__doc__},
155
156
static PyObject *
157
set_union_impl(PySetObject *so, PyObject * const *others,
158
               Py_ssize_t others_length);
159
160
static PyObject *
161
set_union(PyObject *so, PyObject *const *args, Py_ssize_t nargs)
162
4
{
163
4
    PyObject *return_value = NULL;
164
4
    PyObject * const *others;
165
4
    Py_ssize_t others_length;
166
167
4
    others = args;
168
4
    others_length = nargs;
169
4
    return_value = set_union_impl((PySetObject *)so, others, others_length);
170
171
4
    return return_value;
172
4
}
173
174
PyDoc_STRVAR(set_intersection_multi__doc__,
175
"intersection($self, /, *others)\n"
176
"--\n"
177
"\n"
178
"Return a new set with elements common to the set and all others.");
179
180
#define SET_INTERSECTION_MULTI_METHODDEF    \
181
    {"intersection", _PyCFunction_CAST(set_intersection_multi), METH_FASTCALL, set_intersection_multi__doc__},
182
183
static PyObject *
184
set_intersection_multi_impl(PySetObject *so, PyObject * const *others,
185
                            Py_ssize_t others_length);
186
187
static PyObject *
188
set_intersection_multi(PyObject *so, PyObject *const *args, Py_ssize_t nargs)
189
8
{
190
8
    PyObject *return_value = NULL;
191
8
    PyObject * const *others;
192
8
    Py_ssize_t others_length;
193
194
8
    others = args;
195
8
    others_length = nargs;
196
8
    return_value = set_intersection_multi_impl((PySetObject *)so, others, others_length);
197
198
8
    return return_value;
199
8
}
200
201
PyDoc_STRVAR(set_intersection_update_multi__doc__,
202
"intersection_update($self, /, *others)\n"
203
"--\n"
204
"\n"
205
"Update the set, keeping only elements found in it and all others.");
206
207
#define SET_INTERSECTION_UPDATE_MULTI_METHODDEF    \
208
    {"intersection_update", _PyCFunction_CAST(set_intersection_update_multi), METH_FASTCALL, set_intersection_update_multi__doc__},
209
210
static PyObject *
211
set_intersection_update_multi_impl(PySetObject *so, PyObject * const *others,
212
                                   Py_ssize_t others_length);
213
214
static PyObject *
215
set_intersection_update_multi(PyObject *so, PyObject *const *args, Py_ssize_t nargs)
216
0
{
217
0
    PyObject *return_value = NULL;
218
0
    PyObject * const *others;
219
0
    Py_ssize_t others_length;
220
221
0
    others = args;
222
0
    others_length = nargs;
223
0
    return_value = set_intersection_update_multi_impl((PySetObject *)so, others, others_length);
224
225
0
    return return_value;
226
0
}
227
228
PyDoc_STRVAR(set_isdisjoint__doc__,
229
"isdisjoint($self, other, /)\n"
230
"--\n"
231
"\n"
232
"Return True if two sets have a null intersection.");
233
234
#define SET_ISDISJOINT_METHODDEF    \
235
    {"isdisjoint", (PyCFunction)set_isdisjoint, METH_O, set_isdisjoint__doc__},
236
237
static PyObject *
238
set_isdisjoint_impl(PySetObject *so, PyObject *other);
239
240
static PyObject *
241
set_isdisjoint(PyObject *so, PyObject *other)
242
71.8k
{
243
71.8k
    PyObject *return_value = NULL;
244
245
71.8k
    Py_BEGIN_CRITICAL_SECTION2(so, other);
246
71.8k
    return_value = set_isdisjoint_impl((PySetObject *)so, other);
247
71.8k
    Py_END_CRITICAL_SECTION2();
248
249
71.8k
    return return_value;
250
71.8k
}
251
252
PyDoc_STRVAR(set_difference_update__doc__,
253
"difference_update($self, /, *others)\n"
254
"--\n"
255
"\n"
256
"Update the set, removing elements found in others.");
257
258
#define SET_DIFFERENCE_UPDATE_METHODDEF    \
259
    {"difference_update", _PyCFunction_CAST(set_difference_update), METH_FASTCALL, set_difference_update__doc__},
260
261
static PyObject *
262
set_difference_update_impl(PySetObject *so, PyObject * const *others,
263
                           Py_ssize_t others_length);
264
265
static PyObject *
266
set_difference_update(PyObject *so, PyObject *const *args, Py_ssize_t nargs)
267
0
{
268
0
    PyObject *return_value = NULL;
269
0
    PyObject * const *others;
270
0
    Py_ssize_t others_length;
271
272
0
    others = args;
273
0
    others_length = nargs;
274
0
    return_value = set_difference_update_impl((PySetObject *)so, others, others_length);
275
276
0
    return return_value;
277
0
}
278
279
PyDoc_STRVAR(set_difference_multi__doc__,
280
"difference($self, /, *others)\n"
281
"--\n"
282
"\n"
283
"Return a new set with elements in the set that are not in the others.");
284
285
#define SET_DIFFERENCE_MULTI_METHODDEF    \
286
    {"difference", _PyCFunction_CAST(set_difference_multi), METH_FASTCALL, set_difference_multi__doc__},
287
288
static PyObject *
289
set_difference_multi_impl(PySetObject *so, PyObject * const *others,
290
                          Py_ssize_t others_length);
291
292
static PyObject *
293
set_difference_multi(PyObject *so, PyObject *const *args, Py_ssize_t nargs)
294
0
{
295
0
    PyObject *return_value = NULL;
296
0
    PyObject * const *others;
297
0
    Py_ssize_t others_length;
298
299
0
    others = args;
300
0
    others_length = nargs;
301
0
    return_value = set_difference_multi_impl((PySetObject *)so, others, others_length);
302
303
0
    return return_value;
304
0
}
305
306
PyDoc_STRVAR(set_symmetric_difference_update__doc__,
307
"symmetric_difference_update($self, other, /)\n"
308
"--\n"
309
"\n"
310
"Update the set, keeping only elements found in either set, but not in both.");
311
312
#define SET_SYMMETRIC_DIFFERENCE_UPDATE_METHODDEF    \
313
    {"symmetric_difference_update", (PyCFunction)set_symmetric_difference_update, METH_O, set_symmetric_difference_update__doc__},
314
315
static PyObject *
316
set_symmetric_difference_update_impl(PySetObject *so, PyObject *other);
317
318
static PyObject *
319
set_symmetric_difference_update(PyObject *so, PyObject *other)
320
0
{
321
0
    PyObject *return_value = NULL;
322
323
0
    return_value = set_symmetric_difference_update_impl((PySetObject *)so, other);
324
325
0
    return return_value;
326
0
}
327
328
PyDoc_STRVAR(set_symmetric_difference__doc__,
329
"symmetric_difference($self, other, /)\n"
330
"--\n"
331
"\n"
332
"Return a new set with elements in either the set or other but not both.");
333
334
#define SET_SYMMETRIC_DIFFERENCE_METHODDEF    \
335
    {"symmetric_difference", (PyCFunction)set_symmetric_difference, METH_O, set_symmetric_difference__doc__},
336
337
static PyObject *
338
set_symmetric_difference_impl(PySetObject *so, PyObject *other);
339
340
static PyObject *
341
set_symmetric_difference(PyObject *so, PyObject *other)
342
0
{
343
0
    PyObject *return_value = NULL;
344
345
0
    Py_BEGIN_CRITICAL_SECTION2(so, other);
346
0
    return_value = set_symmetric_difference_impl((PySetObject *)so, other);
347
0
    Py_END_CRITICAL_SECTION2();
348
349
0
    return return_value;
350
0
}
351
352
PyDoc_STRVAR(set_issubset__doc__,
353
"issubset($self, other, /)\n"
354
"--\n"
355
"\n"
356
"Report whether another set contains this set.");
357
358
#define SET_ISSUBSET_METHODDEF    \
359
    {"issubset", (PyCFunction)set_issubset, METH_O, set_issubset__doc__},
360
361
static PyObject *
362
set_issubset_impl(PySetObject *so, PyObject *other);
363
364
static PyObject *
365
set_issubset(PyObject *so, PyObject *other)
366
145k
{
367
145k
    PyObject *return_value = NULL;
368
369
145k
    Py_BEGIN_CRITICAL_SECTION2(so, other);
370
145k
    return_value = set_issubset_impl((PySetObject *)so, other);
371
145k
    Py_END_CRITICAL_SECTION2();
372
373
145k
    return return_value;
374
145k
}
375
376
PyDoc_STRVAR(set_issuperset__doc__,
377
"issuperset($self, other, /)\n"
378
"--\n"
379
"\n"
380
"Report whether this set contains another set.");
381
382
#define SET_ISSUPERSET_METHODDEF    \
383
    {"issuperset", (PyCFunction)set_issuperset, METH_O, set_issuperset__doc__},
384
385
static PyObject *
386
set_issuperset_impl(PySetObject *so, PyObject *other);
387
388
static PyObject *
389
set_issuperset(PyObject *so, PyObject *other)
390
7.36k
{
391
7.36k
    PyObject *return_value = NULL;
392
393
7.36k
    Py_BEGIN_CRITICAL_SECTION2(so, other);
394
7.36k
    return_value = set_issuperset_impl((PySetObject *)so, other);
395
7.36k
    Py_END_CRITICAL_SECTION2();
396
397
7.36k
    return return_value;
398
7.36k
}
399
400
PyDoc_STRVAR(set_add__doc__,
401
"add($self, object, /)\n"
402
"--\n"
403
"\n"
404
"Add an element to a set.\n"
405
"\n"
406
"This has no effect if the element is already present.");
407
408
#define SET_ADD_METHODDEF    \
409
    {"add", (PyCFunction)set_add, METH_O, set_add__doc__},
410
411
static PyObject *
412
set_add_impl(PySetObject *so, PyObject *key);
413
414
static PyObject *
415
set_add(PyObject *so, PyObject *key)
416
13.2M
{
417
13.2M
    PyObject *return_value = NULL;
418
419
13.2M
    Py_BEGIN_CRITICAL_SECTION(so);
420
13.2M
    return_value = set_add_impl((PySetObject *)so, key);
421
13.2M
    Py_END_CRITICAL_SECTION();
422
423
13.2M
    return return_value;
424
13.2M
}
425
426
PyDoc_STRVAR(set___contains____doc__,
427
"__contains__($self, object, /)\n"
428
"--\n"
429
"\n"
430
"x.__contains__(y) <==> y in x.");
431
432
#define SET___CONTAINS___METHODDEF    \
433
    {"__contains__", (PyCFunction)set___contains__, METH_O|METH_COEXIST, set___contains____doc__},
434
435
static PyObject *
436
set___contains___impl(PySetObject *so, PyObject *key);
437
438
static PyObject *
439
set___contains__(PyObject *so, PyObject *key)
440
2.14M
{
441
2.14M
    PyObject *return_value = NULL;
442
443
2.14M
    return_value = set___contains___impl((PySetObject *)so, key);
444
445
2.14M
    return return_value;
446
2.14M
}
447
448
PyDoc_STRVAR(frozenset___contains____doc__,
449
"__contains__($self, object, /)\n"
450
"--\n"
451
"\n"
452
"x.__contains__(y) <==> y in x.");
453
454
#define FROZENSET___CONTAINS___METHODDEF    \
455
    {"__contains__", (PyCFunction)frozenset___contains__, METH_O|METH_COEXIST, frozenset___contains____doc__},
456
457
static PyObject *
458
frozenset___contains___impl(PySetObject *so, PyObject *key);
459
460
static PyObject *
461
frozenset___contains__(PyObject *so, PyObject *key)
462
3.52k
{
463
3.52k
    PyObject *return_value = NULL;
464
465
3.52k
    return_value = frozenset___contains___impl((PySetObject *)so, key);
466
467
3.52k
    return return_value;
468
3.52k
}
469
470
PyDoc_STRVAR(set_remove__doc__,
471
"remove($self, object, /)\n"
472
"--\n"
473
"\n"
474
"Remove an element from a set; it must be a member.\n"
475
"\n"
476
"If the element is not a member, raise a KeyError.");
477
478
#define SET_REMOVE_METHODDEF    \
479
    {"remove", (PyCFunction)set_remove, METH_O, set_remove__doc__},
480
481
static PyObject *
482
set_remove_impl(PySetObject *so, PyObject *key);
483
484
static PyObject *
485
set_remove(PyObject *so, PyObject *key)
486
0
{
487
0
    PyObject *return_value = NULL;
488
489
0
    Py_BEGIN_CRITICAL_SECTION(so);
490
0
    return_value = set_remove_impl((PySetObject *)so, key);
491
0
    Py_END_CRITICAL_SECTION();
492
493
0
    return return_value;
494
0
}
495
496
PyDoc_STRVAR(set_discard__doc__,
497
"discard($self, object, /)\n"
498
"--\n"
499
"\n"
500
"Remove an element from a set if it is a member.\n"
501
"\n"
502
"Unlike set.remove(), the discard() method does not raise\n"
503
"an exception when an element is missing from the set.");
504
505
#define SET_DISCARD_METHODDEF    \
506
    {"discard", (PyCFunction)set_discard, METH_O, set_discard__doc__},
507
508
static PyObject *
509
set_discard_impl(PySetObject *so, PyObject *key);
510
511
static PyObject *
512
set_discard(PyObject *so, PyObject *key)
513
264
{
514
264
    PyObject *return_value = NULL;
515
516
264
    Py_BEGIN_CRITICAL_SECTION(so);
517
264
    return_value = set_discard_impl((PySetObject *)so, key);
518
264
    Py_END_CRITICAL_SECTION();
519
520
264
    return return_value;
521
264
}
522
523
PyDoc_STRVAR(set___reduce____doc__,
524
"__reduce__($self, /)\n"
525
"--\n"
526
"\n"
527
"Return state information for pickling.");
528
529
#define SET___REDUCE___METHODDEF    \
530
    {"__reduce__", (PyCFunction)set___reduce__, METH_NOARGS, set___reduce____doc__},
531
532
static PyObject *
533
set___reduce___impl(PySetObject *so);
534
535
static PyObject *
536
set___reduce__(PyObject *so, PyObject *Py_UNUSED(ignored))
537
0
{
538
0
    PyObject *return_value = NULL;
539
540
0
    Py_BEGIN_CRITICAL_SECTION(so);
541
0
    return_value = set___reduce___impl((PySetObject *)so);
542
0
    Py_END_CRITICAL_SECTION();
543
544
0
    return return_value;
545
0
}
546
547
PyDoc_STRVAR(set___sizeof____doc__,
548
"__sizeof__($self, /)\n"
549
"--\n"
550
"\n"
551
"S.__sizeof__() -> size of S in memory, in bytes.");
552
553
#define SET___SIZEOF___METHODDEF    \
554
    {"__sizeof__", (PyCFunction)set___sizeof__, METH_NOARGS, set___sizeof____doc__},
555
556
static PyObject *
557
set___sizeof___impl(PySetObject *so);
558
559
static PyObject *
560
set___sizeof__(PyObject *so, PyObject *Py_UNUSED(ignored))
561
0
{
562
0
    PyObject *return_value = NULL;
563
564
0
    Py_BEGIN_CRITICAL_SECTION(so);
565
0
    return_value = set___sizeof___impl((PySetObject *)so);
566
0
    Py_END_CRITICAL_SECTION();
567
568
0
    return return_value;
569
0
}
570
/*[clinic end generated code: output=5d794137d2614aaf input=a9049054013a1b77]*/