/src/cpython/Objects/clinic/boolobject.c.h
Line | Count | Source |
1 | | /*[clinic input] |
2 | | preserve |
3 | | [clinic start generated code]*/ |
4 | | |
5 | | #include "pycore_modsupport.h" // _PyArg_CheckPositional() |
6 | | |
7 | | PyDoc_STRVAR(bool_new__doc__, |
8 | | "bool(object=False, /)\n" |
9 | | "--\n" |
10 | | "\n" |
11 | | "Returns True when the argument is true, False otherwise.\n" |
12 | | "\n" |
13 | | "The builtins True and False are the only two instances of the class\n" |
14 | | "bool. The class bool is a subclass of the class int, and cannot be\n" |
15 | | "subclassed."); |
16 | | |
17 | | static PyObject * |
18 | | bool_new_impl(PyTypeObject *type, PyObject *x); |
19 | | |
20 | | static PyObject * |
21 | | bool_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
22 | 0 | { |
23 | 0 | PyObject *return_value = NULL; |
24 | 0 | PyTypeObject *base_tp = &PyBool_Type; |
25 | 0 | PyObject *x = Py_False; |
26 | |
|
27 | 0 | if ((type == base_tp || type->tp_init == base_tp->tp_init) && |
28 | 0 | !_PyArg_NoKeywords("bool", kwargs)) { |
29 | 0 | goto exit; |
30 | 0 | } |
31 | 0 | if (!_PyArg_CheckPositional("bool", PyTuple_GET_SIZE(args), 0, 1)) { |
32 | 0 | goto exit; |
33 | 0 | } |
34 | 0 | if (PyTuple_GET_SIZE(args) < 1) { |
35 | 0 | goto skip_optional; |
36 | 0 | } |
37 | 0 | x = PyTuple_GET_ITEM(args, 0); |
38 | 0 | skip_optional: |
39 | 0 | return_value = bool_new_impl(type, x); |
40 | |
|
41 | 0 | exit: |
42 | 0 | return return_value; |
43 | 0 | } |
44 | | |
45 | | static PyObject * |
46 | | bool_vectorcall(PyObject *type, PyObject *const *args, |
47 | | size_t nargsf, PyObject *kwnames) |
48 | 15.1k | { |
49 | 15.1k | PyObject *return_value = NULL; |
50 | 15.1k | Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); |
51 | 15.1k | PyObject *x = Py_False; |
52 | | |
53 | 15.1k | assert(_PyType_CAST(type)->tp_new == bool_new); |
54 | | /* Make sure the type object is immutable: the generated |
55 | | * vectorcall doesn't deal e.g. with users reassigning __init__. */ |
56 | 15.1k | assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE)); |
57 | 15.1k | if (!_PyArg_NoKwnames("bool", kwnames)) { |
58 | 0 | goto exit; |
59 | 0 | } |
60 | 15.1k | if (!_PyArg_CheckPositional("bool", nargs, 0, 1)) { |
61 | 0 | goto exit; |
62 | 0 | } |
63 | 15.1k | if (nargs < 1) { |
64 | 0 | goto skip_optional; |
65 | 0 | } |
66 | 15.1k | x = args[0]; |
67 | 15.1k | skip_optional: |
68 | 15.1k | return_value = bool_new_impl(_PyType_CAST(type), x); |
69 | | |
70 | 15.1k | exit: |
71 | 15.1k | return return_value; |
72 | 15.1k | } |
73 | | /*[clinic end generated code: output=c7be32f9d1f3e07a input=a9049054013a1b77]*/ |