Issue: Build failures with Cython 3.0.0b1
Author: mgorny
State: closed
Created: 2023-02-27 17:48:43

Cython 3.0.0 has released its first beta, meaning that 3.0.0 final will be out sooner than later. Right now peewee fails to build with it:

```
$ python setup.py build
Compiling playhouse/_sqlite_udf.pyx because it changed.
Compiling playhouse/_sqlite_ext.pyx because it changed.
[1/2] Cythonizing playhouse/_sqlite_ext.pyx
/tmp/peewee/venv/lib/python3.11/site-packages/Cython/Compiler/Main.py:370: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /tmp/peewee/playhouse/_sqlite_ext.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)

Error compiling Cython file:
------------------------------------------------------------
...
            pIdxInfo.estimatedCost = <double>1
            pIdxInfo.estimatedRows = 10
        else:
            # Penalize score based on number of missing params.
            pIdxInfo.estimatedCost = <double>10000000000000 * <double>(nParams - nArg)
            pIdxInfo.estimatedRows = 10 ** (nParams - nArg)
                                        ^
------------------------------------------------------------

playhouse/_sqlite_ext.pyx:608:40: Cannot assign type 'double' to 'sqlite3_int64'

Error compiling Cython file:
------------------------------------------------------------
...

        self._commit_hook = fn
        if fn is None:
            sqlite3_commit_hook(self.conn.db, NULL, NULL)
        else:
            sqlite3_commit_hook(self.conn.db, _commit_callback, <void *>fn)
                                              ^
------------------------------------------------------------

playhouse/_sqlite_ext.pyx:1463:46: Cannot assign type 'int (void *) except? -1 nogil' to 'int (*)(void *) noexcept nogil'

Error compiling Cython file:
------------------------------------------------------------
...

        self._rollback_hook = fn
        if fn is None:
            sqlite3_rollback_hook(self.conn.db, NULL, NULL)
        else:
            sqlite3_rollback_hook(self.conn.db, _rollback_callback, <void *>fn)
                                                ^
------------------------------------------------------------

playhouse/_sqlite_ext.pyx:1473:48: Cannot assign type 'void (void *) except * nogil' to 'void (*)(void *) noexcept nogil'

Error compiling Cython file:
------------------------------------------------------------
...

        self._update_hook = fn
        if fn is None:
            sqlite3_update_hook(self.conn.db, NULL, NULL)
        else:
            sqlite3_update_hook(self.conn.db, _update_callback, <void *>fn)
                                              ^
------------------------------------------------------------

playhouse/_sqlite_ext.pyx:1483:46: Cannot assign type 'void (void *, int, const char *, const char *, sqlite3_int64) except * nogil' to 'void (*)(void *, int, char *, char *, sqlite3_int64) noexcept nogil'

Error compiling Cython file:
------------------------------------------------------------
...
        """
        if not self.conn.initialized or not self.conn.db:
            return False

        cdef sqlite3_int64 n = timeout * 1000
        sqlite3_busy_handler(self.conn.db, _aggressive_busy_handler, <void *>n)
                                           ^
------------------------------------------------------------

playhouse/_sqlite_ext.pyx:1494:43: Cannot assign type 'int (void *, int) except? -1 nogil' to 'int (*)(void *, int) noexcept nogil'
Traceback (most recent call last):
  File "/tmp/peewee/setup.py", line 185, in <module>
    _do_setup(extension_support, sqlite_extension_support)
  File "/tmp/peewee/setup.py", line 180, in _do_setup
    ext_modules=cythonize(ext_modules))
                ^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/peewee/venv/lib/python3.11/site-packages/Cython/Build/Dependencies.py", line 1134, in cythonize
    cythonize_one(*args)
  File "/tmp/peewee/venv/lib/python3.11/site-packages/Cython/Build/Dependencies.py", line 1301, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: playhouse/_sqlite_ext.pyx
```

To reproduce:
```
pip install Cython==3.0.0b1
python setup.py build
```

Thank you, I think I got 'em in the above commit.

Thanks, seems to build now. Note that there's still this warning though:

```
[1/2] Cythonizing playhouse/_sqlite_ext.pyx
/tmp/peewee/venv/lib/python3.11/site-packages/Cython/Compiler/Main.py:370: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /tmp/peewee/playhouse/_sqlite_ext.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
[2/2] Cythonizing playhouse/_sqlite_udf.pyx
/tmp/peewee/venv/lib/python3.11/site-packages/Cython/Compiler/Main.py:370: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /tmp/peewee/playhouse/_sqlite_udf.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
```

Yeah I'm going to have to spend some time understanding the ramifications of setting the lang level directive. It should probably just be 3 but like I said, not sure the ramifications of that yet and tests are passing so I'll plan on keeping an eye on it.