# Feature or enhancement

In Python 3.13 alpha1, I removed the private _PyLong_NumBits() function. It seems like this function is used by **pywin32** and **MariaDB** projects: see issue gh-119336.

I propose to add a public function to replace it:

```
Py_ssize_t _PyLong_GetNumBits(PyObject *obj);
```

* Return the number of bits on success: greater than or equal to zero.
* Set an exception and return ``-1`` on error.
* Set an `OverflowError` exception, and return ``-1`` if the number of bits doesn't fit into ``Py_ssize_t``.

The C function is similar to the Python `int.bit_length()` method.

See also the [proposed PyLong_GetSign() function](https://github.com/capi-workgroup/decisions/issues/19#issuecomment-2088230212).

<!-- gh-linked-prs -->
### Linked PRs
* gh-119715
<!-- /gh-linked-prs -->

[C API] Add PyLong_GetNumBits() function
This is a GitHub Issue
repo:cpython
owner:python
Title : [C API] Add PyLong_GetNumBits() function
Issue date:

--- start body ---
# Feature or enhancement

In Python 3.13 alpha1, I removed the private _PyLong_NumBits() function. It seems like this function is used by **pywin32** and **MariaDB** projects: see issue gh-119336.

I propose to add a public function to replace it:

```
Py_ssize_t _PyLong_GetNumBits(PyObject *obj);
```

* Return the number of bits on success: greater than or equal to zero.
* Set an exception and return ``-1`` on error.
* Set an `OverflowError` exception, and return ``-1`` if the number of bits doesn't fit into ``Py_ssize_t``.

The C function is similar to the Python `int.bit_length()` method.

See also the [proposed PyLong_GetSign() function](https://github.com/capi-workgroup/decisions/issues/19#issuecomment-2088230212).

<!-- gh-linked-prs -->
### Linked PRs
* gh-119715
<!-- /gh-linked-prs -->

--- end body ---
