8000 [ENH] Improve the error message for struct size change · Issue #4366 · cython/cython · GitHub
[go: up one dir, main page]

Skip to content
[ENH] Improve the error message for struct size change #4366
@seberg

Description

@seberg

Opening an issue in cython due to a discussion in NumPy.

The currently ValueError when the size of a struct changed (i.e. shrank), is pretty confusing for users. In the case of NumPy we added (basically private) fields to the end of the ndarray struct. This is perfectly ABI compatible so long there are no subclasses involved. (Subclassing ndarray in cython does not work at all, so nobody is doing it.)

Some projects incorrectly compile against a newer NumPy versions and release older wheels: For them, this is annoying to track down, but I think they are happy to learn. But it seems even some end-users run into it occsionally (since they write their own cython modules).

For NumPy, a solution would be if we could call import_array() before the size check, since I believe that already raises the error correctly (assuming we bump the C-API feature version).

In general, I am not sure what best to do. Maybe just adding additional information saying that typically you should compile using the oldest support version? Or maybe we could add some special feature to end a class definition with a __variable_private__ so that cython can decide to only complain if someone actually subclasses that specific class?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0