Skip to content

Refactor type related error raising into separate utility functions#7680

Merged
scoder merged 9 commits into
cython:masterfrom
scoder:refactor_type_errors
Jun 13, 2026
Merged

Refactor type related error raising into separate utility functions#7680
scoder merged 9 commits into
cython:masterfrom
scoder:refactor_type_errors

Conversation

@scoder

@scoder scoder commented May 10, 2026

Copy link
Copy Markdown
Contributor

… to correctly and efficiently handle the type name formatting.

Closes #7601

…o correctly and efficiently handle the type name formatting.
@da-woods

Copy link
Copy Markdown
Contributor

Very superficial comment, but would it make more sense in Exceptions.c rather than Object handling.c

@scoder

scoder commented May 10, 2026

Copy link
Copy Markdown
Contributor Author

would it make more sense in Exceptions.c rather than Object handling.c

Hmm, we already have a longer list of exception raising functions in ObjectHandling.c that are related to handling objects in various ways, but we don't currently have special exception raising functions in Exceptions.c, just code to handle Python style exception raising and propagation. I don't think the functions should go there.

@da-woods

Copy link
Copy Markdown
Contributor

The basic idea here definitely seems like an improvement to me, although I'm away from a proper computer at the moment so haven't had a detailed look.

(Obviously there still looks to be one build issue though)

@scoder

scoder commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

Obviously there still looks to be one build issue though

I think I fixed the Limited API build problem, but the Py3.15 issue also applies to master and needs investigation. It seems that all End-to-End tests are failing since yesterday (2026-05-11) because they can't find distutils any more. The last setuptools release already dates a while back, and Py3.15b1 also isn't from exactly yesterday, so I can't see an obvious change that broke this. I'll try to dig into it.

(EDIT: obviously, the Sanitizers jobs use the latest CPython main branch, so there might have been a change between 3.15b1 and now that broke this.)

(EDIT2: I found python/cpython#149583 to be the most probable reason.)

@scoder

scoder commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

This PR branch is failing on CPython main in the same way as Cython master, and none of it is specific to either Py3.15 or this PR. So I deem this done and worth a second look.

@da-woods da-woods left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes agree this cuts down some of the repetitive bits a lot.

I probably wouldn't have bothered with all different variations (just because I doubt that I'll remember that they all exist in future) but that's really just personal taste I think.

Comment thread Cython/Utility/ObjectHandling.c Outdated
Comment on lines +3027 to +3028
#define __Pyx_RaiseTypeErrorWithObjectType(message, obj) __Pyx_RaiseTypeErrorWithType(message, Py_TYPE(obj))
#define __Pyx_RaiseTypeErrorWithType(message, type_obj) __Pyx_RaiseErrorWithType(PyExc_TypeError, message, type_obj)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely doesn't do any harm, but I probably wouldn't have bothered with these two macros (vs just passing TypeError to __Pyx_RaiseErrorWithType or __Pyx_RaiseErrorWithObjectType

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered it the "normal" case to raise a TypeError, thus the extra macros. But thanks for pointing at this, I found some that were really unnecessary in retrospect.

Mark the corresponding error handling functions as potentially unused.
@scoder scoder merged commit 576bd2a into cython:master Jun 13, 2026
112 checks passed
@scoder scoder deleted the refactor_type_errors branch June 13, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants