Skip to content
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

cpdef functions using noexcept #37888

Open
tornaria opened this issue Apr 28, 2024 · 1 comment
Open

cpdef functions using noexcept #37888

tornaria opened this issue Apr 28, 2024 · 1 comment

Comments

@tornaria
Copy link
Contributor

          regarding `cpdef` + `noexcept`:
$ git grep cpdef | grep noexcept | wc -l
341

so there are quite a few of these in the repo.

Originally posted by @dimpase in #37792 (comment)

It seems cpdef functions don't show warnings for misuse of noexcept. We should investigate about this.

@tornaria
Copy link
Contributor Author

First thoughts:

  • a cpdef function is equivalent to a cdef function + a def wrapper. I think the noexcept (or other except clauses) apply only to the cdef function since a def function must have the standard python semantics (iirc a python function always return a python object as a pointer with null meaning check for exceptions).
  • by the same token, any cdef or cpdef function that returns a python object should not be noexcept as cython will ignore the noexcept (with a warning in the case of cdef functions, but maybe no warning for cpdef functions: should investigate and if so file an issue upstream)
  • cpdef functions that return C types are in principle allowed to use noexcept (unless they call raise). In this case the def wrapper will convert the C type into a python object iiuc.
  • Some c types that show up in the 341 matches: int, long, unsigned long, bint, size_t, double.

This leaves us with 28 cases to check:

$ git grep cpdef.*noexcept | grep -E -v "\<cpdef +(inline +)?(int|(unsigned )?long|bint|size_t|double) "
src/sage/graphs/bliss.pyx:cpdef canonical_form(G, partition=None, return_graph=False, use_edge_labels=True, certificate=False) noexcept:
src/sage/graphs/bliss.pyx:cpdef automorphism_group(G, partition=None, use_edge_labels=True) noexcept:
src/sage/libs/coxeter3/coxeter.pxd:    cpdef object full_context(self) noexcept
src/sage/libs/coxeter3/coxeter.pxd:    cpdef CoxGroup parent_group(self) noexcept
src/sage/libs/coxeter3/coxeter.pyx:    cpdef full_context(self) noexcept:
src/sage/libs/coxeter3/coxeter.pyx:    cpdef CoxGroup parent_group(self) noexcept:
src/sage/libs/gap/element.pxd:    cpdef UInt record_name_to_index(self, name) noexcept
src/sage/libs/gap/element.pyx:    cpdef UInt record_name_to_index(self, name) noexcept:
src/sage/libs/sirocco.pyx:cpdef list[list] contpath_mp(int deg, list values, RealNumber y0r, RealNumber y0i, int prec) noexcept:
src/sage/libs/sirocco.pyx:cpdef list[list] contpath_mp_comps(int deg, list values, RealNumber y0r, RealNumber y0i, int prec, list otherdegs, list othercoefs) noexcept:
src/sage/libs/sirocco.pyx:cpdef list[list] contpath(int deg, list values, double y0r, double y0i) noexcept:
src/sage/libs/sirocco.pyx:cpdef list[list] contpath_comps(int deg, list values, double y0r, double y0i, list otherdegrees, list othercoefs) noexcept:
src/sage/matrix/matrix_gfpn_dense.pxd:    cpdef fel_to_field(self, FEL x) noexcept
src/sage/matrix/matrix_gfpn_dense.pxd:    cpdef Matrix_gfpn_dense get_slice(self, Py_ssize_t i, Py_ssize_t j) noexcept
src/sage/matrix/matrix_gfpn_dense.pxd:    cpdef list _rowlist_(self, i, j=*) noexcept
src/sage/matrix/matrix_gfpn_dense.pxd:    cpdef Matrix_gfpn_dense _multiply_classical(Matrix_gfpn_dense self, Matrix_gfpn_dense right) noexcept
src/sage/matrix/matrix_gfpn_dense.pxd:    cpdef Matrix_gfpn_dense _multiply_strassen(Matrix_gfpn_dense self, Matrix_gfpn_dense right, cutoff=*) noexcept
src/sage/matrix/matrix_gfpn_dense.pyx:    cpdef fel_to_field(self, FEL x) noexcept:
src/sage/matrix/matrix_gfpn_dense.pyx:    cpdef fel_to_field(self, FEL x) noexcept:
src/sage/matrix/matrix_gfpn_dense.pyx:    cpdef Matrix_gfpn_dense get_slice(self, Py_ssize_t i, Py_ssize_t j) noexcept:
src/sage/matrix/matrix_gfpn_dense.pyx:    cpdef _richcmp_(left, right, int op) noexcept:
src/sage/matrix/matrix_gfpn_dense.pyx:    cpdef list _rowlist_(self, i, j=-1) noexcept:
src/sage/matrix/matrix_gfpn_dense.pyx:    cpdef _add_(self, right) noexcept:
src/sage/matrix/matrix_gfpn_dense.pyx:    cpdef _sub_(self, right) noexcept:
src/sage/matrix/matrix_gfpn_dense.pyx:    cpdef _lmul_(self, Element right) noexcept:
src/sage/matrix/matrix_gfpn_dense.pyx:    cpdef Matrix_gfpn_dense _multiply_classical(Matrix_gfpn_dense self, Matrix_gfpn_dense right) noexcept:
src/sage/matrix/matrix_gfpn_dense.pyx:    cpdef Matrix_gfpn_dense _multiply_strassen(Matrix_gfpn_dense self, Matrix_gfpn_dense right, cutoff=0) noexcept:
src/sage/matrix/matrix_gfpn_dense.pyx:    cpdef _echelon_in_place(self, str algorithm) noexcept:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants