# C API: \`PyArg\_Parse\` to a C \`bool\` (\`\<stdbool.h\>\`)

**URL:** <https://discuss.python.org/t/c-api-pyarg-parse-to-a-c-bool-stdbool-h/106189>\
**Category:** Ideas\
**Tags:** c-api\
**Created:** [February 17, 2026, 11:01am UTC](https://discuss.python.org/t/c-api-pyarg-parse-to-a-c-bool-stdbool-h/106189 "2026-02-17T11:01:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucascolley](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/lucascolley/32/21748_2.png) [@lucascolley](https://discuss.python.org/u/lucascolley)\
**Post date:** [February 17, 2026, 11:01am UTC](https://discuss.python.org/t/c-api-pyarg-parse-to-a-c-bool-stdbool-h/106189/1 "2026-02-17T11:01:22Z")

</div>

Hi! I’m quite new to C, and one thing that surprised me while looking into SciPy’s C extensions is how Python `bool`s are typically converted to C `int`s under the hood. It seems the idiomatic way for this is the `p` (predicate) format code described at [Parsing arguments and building values — Python 3.14.3 documentation](https://docs.python.org/3/c-api/arg.html#other-objects).

I think it would be nice to have a format code which parses truthy/falsy Python objects to a C `bool` — `P` maybe? Currently it seems one has to do an additional cast after using `PyArg_Parse`, which might nullify any readability gained from using a `bool` instead of an `int` pretending to be boolean.

What do you think? Do developers just need to get used to `int`s pretending to be `bool`s, or could we add to the API to make it easier for extension developers to make their C code ever so slightly more Pythonic?

---

<div class="post-metadata">

**Author:** ![MRAB](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@MRAB](https://discuss.python.org/u/MRAB)\
**Post date:** [February 17, 2026, 4:11pm UTC](https://discuss.python.org/t/c-api-pyarg-parse-to-a-c-bool-stdbool-h/106189/2 "2026-02-17T16:11:17Z")

</div>

The `bool` type was added to C in the C99 standard. CPython predates that by some years.

---

<div class="post-metadata">

**Author:** ![lucascolley](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/lucascolley/32/21748_2.png) [@lucascolley](https://discuss.python.org/u/lucascolley)\
**Post date:** [February 17, 2026, 4:29pm UTC](https://discuss.python.org/t/c-api-pyarg-parse-to-a-c-bool-stdbool-h/106189/3 "2026-02-17T16:29:49Z")

</div>

Indeed, but `bool` is fair game since Python 3.11 (or even Python 3.6) according to [PEP 7 – Style Guide for C Code | peps.python.org](https://peps.python.org/pep-0007/#c-standards), right?

---

<div class="post-metadata">

**Author:** ![encukou](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/encukou/32/2461_2.png) [@encukou](https://discuss.python.org/u/encukou)\
**Post date:** [February 17, 2026, 4:53pm UTC](https://discuss.python.org/t/c-api-pyarg-parse-to-a-c-bool-stdbool-h/106189/4 "2026-02-17T16:53:02Z")

</div>

PEP 7 is just a style guide.  
Adding a new C11 feature to the public headers is covered in the [devguide](https://devguide.python.org/developer-workflow/c-api/#public-c-api):

> While the _public_ docs only promise compatibility with C11, in practice we only introduce C11 features individually as needed.

I don’t think the benefit is worth it here.

---

<div class="post-metadata">

**Author:** ![lucascolley](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/lucascolley/32/21748_2.png) [@lucascolley](https://discuss.python.org/u/lucascolley)\
**Post date:** [February 17, 2026, 5:50pm UTC](https://discuss.python.org/t/c-api-pyarg-parse-to-a-c-bool-stdbool-h/106189/5 "2026-02-17T17:50:59Z")

</div>

> [@encukou](#):
>
> Adding a new C11 feature

Sorry, I don’t understand — isn’t `bool` C99?

---

<div class="post-metadata">

**Author:** ![da-woods](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/da-woods/32/7507_2.png) [@da-woods](https://discuss.python.org/u/da-woods)\
**Post date:** [February 17, 2026, 6:02pm UTC](https://discuss.python.org/t/c-api-pyarg-parse-to-a-c-bool-stdbool-h/106189/6 "2026-02-17T18:02:02Z")

</div>

I’m not particular convinced it’s worth the effort. But I don’t think this needs any changes to the public headers - because it’s a variadic argument function the ability to pass `bool/_Bool` doesn’t change the signature.

---

<div class="post-metadata">

**Author:** ![tstefan](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@tstefan](https://discuss.python.org/u/tstefan)\
**Post date:** [February 17, 2026, 9:49pm UTC](https://discuss.python.org/t/c-api-pyarg-parse-to-a-c-bool-stdbool-h/106189/7 "2026-02-17T21:49:39Z")

</div>

> [@lucascolley](#):
>
> Sorry, I don’t understand — isn’t `bool` C99?

It is C99. It would be ok to use `bool` in new code in the Cpython codebase. It might also be ok to change `int` to `bool` when modernizing code if this does not affect the API or ABI compatibility.

But for `PyArg_Parse` its not that easy: Currently, if you specify the type as `p`, you have to provide a pointer to an `int` variable, to which `PyArg_Parse` writes the argument to. For backwards compatibility, you cannot change that. The only thing is to add another type specifier, like the `P` you have proposed, to indicate that the corresponding pointer points to a `bool` variable. This means that you would need to provide a second interface that has to be implemented, maintained and tested for long time, possibly indefinitely.

---

<div class="post-metadata">

**Author:** ![lucascolley](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/lucascolley/32/21748_2.png) [@lucascolley](https://discuss.python.org/u/lucascolley)\
**Post date:** [February 17, 2026, 10:23pm UTC](https://discuss.python.org/t/c-api-pyarg-parse-to-a-c-bool-stdbool-h/106189/8 "2026-02-17T22:23:11Z")

</div>

> [@tstefan](#):
>
> The only thing is to add another type specifier, like the `P` you have proposed, to indicate that the corresponding pointer points to a `bool` variable. This means that you would need to provide a second interface that has to be implemented, maintained and tested for long time, possibly indefinitely.

Yep, this was my suggestion. I still think that sounds nice from the user-side, but I have no estimation of maintenance burden (I suppose I thought that one more option to the \mathcal{O}(10) currently available wouldn’t be _too_ bad).

---

<div class="post-metadata">

**Author:** ![encukou](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/encukou/32/2461_2.png) [@encukou](https://discuss.python.org/u/encukou)\
**Post date:** [February 18, 2026, 12:27pm UTC](https://discuss.python.org/t/c-api-pyarg-parse-to-a-c-bool-stdbool-h/106189/9 "2026-02-18T12:27:35Z")

</div>

> isn’t `bool` C99?

Ah, right, my bad.

Count me as -0 then.
