Skip to content

Adopt multi-phase initialisation (PEP 489) #495

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

Merged
merged 1 commit into from
May 29, 2025

Conversation

AA-Turner
Copy link
Contributor

Per #494, this PR effects multi-phase init for MarkupSafe.

I've also added a test to ensure things are working properly.

Thanks,
Adam

Comment on lines +182 to +184
#ifdef Py_mod_gil // Python 3.13+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
#endif
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This replaces the PyUnstable_Module_SetGIL() call, migrating away from experimental/unstable API.

NULL
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "markupsafe._speedups",
.m_size = 0,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

m_size goes from -1 to 0 as we have no module state. -1 is a special sentinel indicating that the module may have global state, which we don't have here.

@AA-Turner
Copy link
Contributor Author

Failure seems unrelated: py3.13: skipped because could not find python interpreter with spec(s): py3.13

@davidism
Copy link
Member

Do I need to do this somehow with PyO3 if we switch to Rust with #438?

@AA-Turner
Copy link
Contributor Author

Do I need to do this somehow with PyO3 if we switch to Rust with #438?

Many binding generators have support for multi-phase (Cython, Pybind, HPy, etc), but sadly PyO3 doesn't yet. There's a draft PR in PyO3/pyo3#5142, though.

I'd be happy to help with multi-phase in Rust should you go forward with that PR; as mentioned this is useful in Sphinx for subinterpreter support so I have an incentive to help!

A

@davidism davidism added this to the 3.0.3 milestone May 29, 2025
@davidism davidism changed the base branch from main to stable May 29, 2025 02:54
@davidism
Copy link
Member

Rebased onto stable. Determined the new test doesn't require a subprocess call. It still fails when run on stable with pytest or tox.

@davidism davidism merged commit e96a84f into pallets:stable May 29, 2025
12 checks passed
@AA-Turner AA-Turner deleted the multi-phase branch May 29, 2025 04:00
@AA-Turner
Copy link
Contributor Author

Thanks David!

A

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.

2 participants