-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[MAINT, Cython] Implicit noexcept
is deprecated in Cython 3.0
#25609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yea, we should do this and follow the advice in the Cython migration guide. The TODOs is listed here: scikit-learn/sklearn/_build_utils/__init__.py Lines 83 to 93 in 872a084
If the changes are compatible with 0.29.33 and 3.0, I am in favor of updating the code now. |
Both replacement of:
are valid for 0.29.33. I can tackle this by doing one submodule at a time perhaps and then c/ping the output of the pip install with Cython3.0? I have updated the issue with a strategy. |
Given this is a simple find and replace, I think it can be big one PR. Here is a quick Python script that does the replacements: import re
from pathlib import Path
from itertools import chain
sklearn_root = Path("sklearn")
pyx_paths = chain(
sklearn_root.glob("**/*.pyx"),
sklearn_root.glob("**/*.pyx.tp"),
sklearn_root.glob("**/*.pxi"),
)
nogil_colon = re.compile(r"\) nogil:")
nogil_except_neg1 = re.compile(r"\) nogil except -1:")
nogil_except_star = re.compile(r"\) nogil except \*:")
for pyx_path in pyx_paths:
orig_contents = pyx_path.read_text()
new_contents = nogil_colon.sub(") noexcept nogil:", orig_contents)
new_contents = nogil_except_neg1.sub(") except -1 nogil:", new_contents)
new_contents = nogil_except_star.sub(") except nogil *:", new_contents)
if new_contents != orig_contents:
pyx_path.write_text(new_contents)
nogil_no_colon = re.compile(r"\) nogil\n")
nogil_except_neg1_no_colon = re.compile(r"\) nogil except -1")
nogil_except_star_no_colon = re.compile(r"\) nogil except \*")
pxd_paths = chain(sklearn_root.glob("**/*.pxd"), sklearn_root.glob("**/*.pxd.tp"))
for pxd_path in pxd_paths:
orig_contents = pxd_path.read_text()
new_contents = nogil_no_colon.sub(") noexcept nogil\n", orig_contents)
new_contents = nogil_except_neg1_no_colon.sub(") except -1 nogil", new_contents)
new_contents = nogil_except_star_no_colon.sub(") except * nogil", new_contents)
if new_contents != orig_contents:
pxd_path.write_text(new_contents) Afterwards, we can remove |
Hi,
I was trying some stuff out on Cython 3.0, and I saw a bunch of errors of the form:
It seems that anytime
nogil
is used, thenoexcept
keyword must be typed. Is this of interest to patch?Proposed Solution
It is thus time to replace the following instances in sklearn to be compatible with Cython3.0+:
nogil
withnoexcept nogil
andnogil except -1
withexcept -1 nogil
By running:
ag "nogil:" -c
You can see the following files are affected. The proposed strategy is to then tackle 1 submodule at a time (or one set of files at a time).
You can run specifically
ag ") nogil:" -Q
, if you want a more fine-grained search.Once the changes are made, one must run the following:
and copy/paste the output for each PR to verify that they have indeed made the changes correctly.
The text was updated successfully, but these errors were encountered: