Skip to content

python: Add test cases for PEP 803/820 ft-compatible limited API#15695

Open
mgorny wants to merge 1 commit intomesonbuild:masterfrom
mgorny:pep803
Open

python: Add test cases for PEP 803/820 ft-compatible limited API#15695
mgorny wants to merge 1 commit intomesonbuild:masterfrom
mgorny:pep803

Conversation

@mgorny
Copy link
Copy Markdown
Contributor

@mgorny mgorny commented Apr 9, 2026

Add a new test case that exercises the limited API code in Python 3.15.0b1. It is run with Python 3.15+, both GIL-enabled (where .abi3.so extension is built) and freethreading (.abi3t.so). The "old" limited API test case is now restricted to GIL-enabled builds only, as the code is not compatible with the new API, and it is cleaner to have separate test cases rather than add conditions to that code.

@mgorny mgorny requested a review from jpakkane as a code owner April 9, 2026 18:34
@rgommers
Copy link
Copy Markdown
Contributor

Thanks for working on this @mgorny.

However, due to a bug in CPython [1]

That [1] was intended as a link it looks like - python/cpython#148267.

@mgorny
Copy link
Copy Markdown
Contributor Author

mgorny commented Apr 13, 2026

Indeed, thanks for noticing. Fixed now.

Copy link
Copy Markdown
Contributor

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

This LGTM module a few very small things. I also verified that abi3.so or the abi3 name isn't used explicitly anywhere, so it's expected that there is no need to explicitly check for abi3t.so either.

Comment thread mesonbuild/modules/python.py Outdated
default_options : ['buildtype=release', 'werror=true'])

py_mod = import('python')
py = py_mod.find_installation()
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.

Nit: more idiomatic to collapse these 2 lines to 1 line and not use a py_mod variable.

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 was copying the existing test, but I suppose I can change that.

py_mod = import('python')
py = py_mod.find_installation()

if py.get_variable('Py_GIL_DISABLED', 0) == 1 and py.language_version().version_compare('<3.15')
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.

Shouldn't this stay? This is not supported on 3.14 Maybe add a code comment saying that limited.c doesn't use PyModExport, hence this test case doesn't support use of the limited API under free-threading? Or extend the error message below to say that. Because I was slightly confused about why this wouldn't work for a second.

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.

addressed, resolving.

}

PyMODINIT_FUNC PyInit_limited(void) {
PyErr_SetString(PyExc_NotImplementedError, "legacy init not supported");
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.

Is this better than not defining the PyInit_ symbol at all?

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.

To be honest, I don't recall anymore why I did it that way in the stable-abi-testing repo, but there was probably a reason. Yes, it's one of these things :-).

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.

Checked upstream, it's done the same way there in the one test package they have:

https://github.com/python/cpython/blob/4ae1a260c7dbada6db099d3335a784b5aae91723/Lib/test/test_cext/extension.c#L145

so resolving.

@eli-schwartz eli-schwartz self-assigned this Apr 13, 2026
@mgorny mgorny force-pushed the pep803 branch 2 times, most recently from b8cad09 to 016b197 Compare April 17, 2026 16:57
Add a new test case that exercises the limited API code in Python
3.15.0b1.  It is run with Python 3.15+, both GIL-enabled (where
`.abi3.so` extension is built) and freethreading (`.abi3t.so`).  The
"old" limited API test case is now restricted to GIL-enabled builds
only, as the code is not compatible with the new API, and it is cleaner
to have separate test cases rather than add conditions to that code.

Signed-off-by: Michał Górny <mgorny@quansight.com>
@mgorny mgorny changed the title python: Add initial support for PEP 803 ABI in Python 3.15.0a8 python: Add test cases for PEP 803/820 ft-compatible limited API May 7, 2026
@mgorny
Copy link
Copy Markdown
Contributor Author

mgorny commented May 7, 2026

Okay, so Python 3.15.0b1 is out.

The bug we were working around is fixed, so I've removed the hack for now. We're still going to need something to switch to abi3t from non-freethreading interpreter but we can do that later. So the PR is now just adding tests for the status quo.

PEP 820 changed the limited API, so I've updated the test cases. I've also rebased on top of master.

Copy link
Copy Markdown
Member

@dcbaker dcbaker left a comment

Choose a reason for hiding this comment

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

This looks good to me. I think @eli-schwartz wanted to look at it as well?

@eli-schwartz
Copy link
Copy Markdown
Member

PEP 820 changed the limited API, so I've updated the test cases. I've also rebased on top of master.

Yup, I was worried about that, and turns out for good reason...

Copy link
Copy Markdown
Contributor

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

Thanks @mgorny, this LGTM now

}

PyMODINIT_FUNC PyInit_limited(void) {
PyErr_SetString(PyExc_NotImplementedError, "legacy init not supported");
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.

Checked upstream, it's done the same way there in the one test package they have:

https://github.com/python/cpython/blob/4ae1a260c7dbada6db099d3335a784b5aae91723/Lib/test/test_cext/extension.c#L145

so resolving.

py_mod = import('python')
py = py_mod.find_installation()

if py.get_variable('Py_GIL_DISABLED', 0) == 1 and py.language_version().version_compare('<3.15')
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.

addressed, resolving.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants