<!-- Thank you for contributing to Pyodide! All improvements are welcome,
     so don't be afraid to make a PR. -->

<!-- [IMPORTANT] Note on CI failures:
     Currently, we are having issues with selenium-based tests.
     Don't panic if the CI fails on your PR because of timeouts.
     It's probably not your fault. We will investigate :) -->

### Description

<!-- Please explain what your PR is about:
     - reasoning for the change
     - some details of updated code
     - any noteworthy choices to be aware of
	Please refer to any related issues by #<issue_id> -->

Working on using pre-commit properly. Will be a series of commits, and undrafted after they are complete.

Rough plan:

- [x] Commit 1: update pre-commit, prepare mypy to run correctly.
- [x] Next commit: apply pre-commit fixes
- [x] Next commit: use pre-commit instead of manual runs inside Makefile.
- [x] Somewhere in between commit: fix manual issues

### Checklists

<!-- Note on checklists:
     If you think some of these steps are not necessary for your PR,
     just remove those checkboxes, or mark them as checked. Otherwise,
     if some checkboxes are left unmarked, we might assume that your PR
     is not ready to be merged and we might keep you waiting -->

style: improve pre-commit. <!-- Thank you for contributing to Pyodide! All improvements are welcome,
     so don't be afraid to make a PR. -->

<!-- [IMPORTANT] Note on CI failures:
     Currently, we are having issues with selenium-based tests.
     Don't panic if the CI fails on your PR because of timeouts.
     It's probably not your fault. We will investigate :) -->

### Description

<!-- Please explain what your PR is about:
     - reasoning for the change
     - some details of updated code
     - any noteworthy choices to be aware of
	Please refer to any related issues by #<issue_id> -->

Working on using pre-commit properly. Will be a series of commits, and undrafted after they are complete.

Rough plan:

- [x] Commit 1: update pre-commit, prepare mypy to run correctly.
- [x] Next commit: apply pre-commit fixes
- [x] Next commit: use pre-commit instead of manual runs inside Makefile.
- [x] Somewhere in between commit: fix manual issues

### Checklists

<!-- Note on checklists:
     If you think some of these steps are not necessary for your PR,
     just remove those checkboxes, or mark them as checked. Otherwise,
     if some checkboxes are left unmarked, we might assume that your PR
     is not ready to be merged and we might keep you waiting -->

#ifndef PYTHON2JS_H
#define PYTHON2JS_H

/** Translate Python objects to JavaScript.
 */
// clang-format off
#define PY_SSIZE_T_CLEAN
#include "Python.h"
// clang-format on
#include "hiwire.h"

/**
 * Do a shallow conversion from python to JavaScript. Convert immutable types
 * with equivalent JavaScript immutable types, but all other types are proxied.
 */
JsRef
python2js(PyObject* x);

/**
 * Like python2js except in the handling of PyProxy creation.
 *
 * If proxies is NULL, will throw an error instead of creating a PyProxy.
 * Otherwise, proxies should be an Array and python2js_track_proxies will add
 * the proxy to the array if one is created.
 */
JsRef
python2js_track_proxies(PyObject* x, JsRef proxies);

/**
 * Convert a Python object to a JavaScript object, copying standard collections
 * into javascript down to specified depth
 * \param x The Python object
 * \param depth The maximum depth to copy
 * \param proxies If this is Null, will raise an error if we have no JavaScript
 *        conversion for a Python object. If not NULL, should be a JavaScript
 *        list. We will add all PyProxies created to the list.
 * \return The JavaScript object -- might be an Error object in the case of an
 *         exception.
 */
JsRef
python2js_with_depth(PyObject* x, int depth, JsRef proxies);

int
python2js_init(PyObject* core);

#endif /* PYTHON2JS_H */

#ifndef PYTHON2JS_H
#define PYTHON2JS_H

/** Translate Python objects to JavaScript.
 */
// clang-format off
#define PY_SSIZE_T_CLEAN
#include "Python.h"
// clang-format on
#include "hiwire.h"

/**
 * Do a shallow conversion from python to JavaScript. Convert immutable types
 * with equivalent JavaScript immutable types, but all other types are proxied.
 */
JsRef
python2js(PyObject* x);

/**
 * Like python2js except in the handling of PyProxy creation.
 *
 * If proxies is NULL, will throw an error instead of creating a PyProxy.
 * Otherwise, proxies should be an Array and python2js_track_proxies will add
 * the proxy to the array if one is created.
 */
JsRef
python2js_track_proxies(PyObject* x, JsRef proxies);

/**
 * Convert a Python object to a JavaScript object, copying standard collections
 * into javascript down to specified depth
 * \param x The Python object
 * \param depth The maximum depth to copy
 * \param proxies If this is Null, will raise an error if we have no JavaScript
 *        conversion for a Python object. If not NULL, should be a JavaScript
 *        list. We will add all PyProxies created to the list.
 * \return The JavaScript object -- might be an Error object in the case of an
 *         exception.
 */
JsRef
python2js_with_depth(PyObject* x, int depth, JsRef proxies);

int
python2js_init(PyObject* core);

#endif /* PYTHON2JS_H */
