pytroll / pyresample

Geospatial image resampling in Python
http://pyresample.readthedocs.org
GNU Lesser General Public License v3.0
344 stars 95 forks source link

Upgrade to Cython 3.0 and check annotations #537

Closed djhoese closed 6 months ago

djhoese commented 1 year ago

Cython 3 has come out and there are a lot of big changes. I've run into a couple gotchas so far and we'll need to be careful. I think we should make sure to force cython>=3 in the pyproject.toml. Issues I've run into so far:

  1. DEF/constants are being deprecated. See https://github.com/cython/cython/issues/4310. However, I haven't found good replacements for some of the use cases so I'm not sure this is the first thing we tackle.
  2. cdef functions now default to exceptions being possible (as if you had done except -1 or similar). For many cases of the code I write this isn't what I want. On nogil functions this is extra bad because it adds a GIL acquire and release to check the error state. The fix is to do noexcept nogil: at the end of the function declaration. Checking the HTML output of cython -a some_module.pyx makes it pretty clear since our nogil functions shouldn't have any yellow (non-C code).
  3. We can and should probably drop the old numpy API by defining in setup.py:
        define_macros = [("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")]