Skip to content

MAINT: Pin Cython to <3.3 - #32393

Closed
eendebakpt wants to merge 3 commits into
numpy:mainfrom
eendebakpt:pin-cython
Closed

eendebakpt wants to merge 3 commits into
numpy:mainfrom
eendebakpt:pin-cython

Conversation

@eendebakpt

Copy link
Copy Markdown
Contributor

PR summary

Cython 3.3.0 changed the limited-API CyFunction layout per abi3 target without updating the shared-type ABI key, so importing extensions built for different targets fails with "Shared Cython type cython_function_or_method has the wrong size". This breaks test_limited_api. Upstream report is cython/cython#7914.

AI Disclosure

Claude was used to investigate the issue.

Cython 3.3.0 changed the limited-API CyFunction layout per abi3 target
without updating the shared-type ABI key, so importing extensions built
for different targets fails with "Shared Cython type
cython_function_or_method has the wrong size". This breaks
test_limited_api on all platforms. See cython/cython#7914.

Co-Authored-By: Claude Fable 5 <[email protected]>
@eendebakpt
eendebakpt marked this pull request as draft August 23, 2026 18:25
The limited-API Cython tests compile extensions at test time with the
Cython installed via test_requirements.txt, so the pin is needed there
too.

Co-Authored-By: Claude Fable 5 <[email protected]>
@eendebakpt
eendebakpt marked this pull request as ready for review August 23, 2026 20:21
@charris charris added the 09 - Backport-Candidate PRs tagged should be backported label Aug 23, 2026
@ngoldbaum

Copy link
Copy Markdown
Member

Thanks! And thanks also for reporting this upstream. I think we need to pin environment.yml as well, see latest commit.

I'll merge this as soon as CI clears.

@rgommers

Copy link
Copy Markdown
Member

I'm not sure if this is the correct fix. The upstream bug report isn't entirely clear, but the problem only occurs when multiple modules inside the same package have different targets, right? If so, that's a corner case that shouldn't occur in the real world, and the better fix is to disable the test until it's addressed in Cython 3.3.x

Comment thread pyproject.toml
requires = [
"meson-python>=0.20.0",
"Cython>=3.1.0", # keep in sync with version check in meson.build
"Cython>=3.1.0,<3.3", # keep in sync with version check in meson.build

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is definitely not necessary, even if the pin in the test requirements is the right call. numpy itself does not use the limited API.

@ngoldbaum

Copy link
Copy Markdown
Member

and the better fix is to disable the test until it's addressed in Cython 3.3.x

Yeah, you're right. Sorry for not thinking this through carefully. I opened #32407.

@rgommers

Copy link
Copy Markdown
Member

A verification and confirmation that it indeed does not happen if the extension modules with different minimum Python versions live in different packages (or don't share a shared utility library?) would be useful. If so, the upstream issue might be invalid or closeable with a doc-only update. It's still not entirely clear to me - the test is obscure.

@ngoldbaum

Copy link
Copy Markdown
Member

#32407 was merged so this one can be closed. Thanks Ralf for reminding me that upper version pins are bad (most of the time).

@da-woods

Copy link
Copy Markdown
Contributor

A verification and confirmation that it indeed does not happen if the extension modules with different minimum Python versions live in different packages

I'm fairly sure it will happen with Cython modules in different packages.

@rgommers

Copy link
Copy Markdown
Member

Okay, thanks for confirming. I still didn't understand why, so I dug a bit - see cython/cython#7914 (comment).

@eendebakpt
eendebakpt deleted the pin-cython branch September 3, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants