Skip to content

Check prerelease interpreters without mutating metadata - #920

Merged
dnicolodi merged 1 commit into
mesonbuild:mainfrom
notatallshaw:fix/prerelease-interpreter-check-20261019
Nov 4, 2026
Merged

dnicolodi merged 1 commit into
mesonbuild:mainfrom
notatallshaw:fix/prerelease-interpreter-check-20261019

Conversation

@notatallshaw

@notatallshaw notatallshaw commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

I plan to deprecate mutability of packaging's core objects to improve performance and hashability. This PR removes mutation of the project's requires-python specifier ahead of that change.

A new __replace__ API will cover callers that need a modified copy in future versions of packaging. The interpreter check doesn't need a copy: it passes prereleases=True to contains(), keeping preview Python versions eligible without changing project metadata.

Comment thread mesonpy/__init__.py Outdated
if platform.python_version().rstrip('+') not in self._metadata.requires_python:
if not self._metadata.requires_python.contains(
platform.python_version().rstrip('+'), prereleases=True
):

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.

I may be reading the packaging documentation wrong, but the default is prereleases=None and this is treated the same as prereleases=True (if this is not the case the documentation may require some clarification). Thus this change does not seem to be needed, namely setting prereleases = True can be simply dropped?

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.

Correct, but this behavior was changed (by me) in packaging 26.0 to correctly match the spec.

So you would need to set packaging >= 26.0 in your pyproject.toml, and then yes, you can remove the line self._metadata.requires_python.prereleases = True.

I can update this PR to do that if you prefer.

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.

Thanks for the explanation. I think the current approach is preferable.

@dnicolodi
dnicolodi force-pushed the fix/prerelease-interpreter-check-20261019 branch 3 times, most recently from dc84b4a to 391e91e Compare November 3, 2026 19:48
@dnicolodi

Copy link
Copy Markdown
Member

I took the freedom to extend the commit message and to apply some cosmetic fixes. @notatallshaw please have a look.

@dnicolodi
dnicolodi force-pushed the fix/prerelease-interpreter-check-20261019 branch from 391e91e to 9e80bd1 Compare November 3, 2026 19:52
@notatallshaw

Copy link
Copy Markdown
Contributor Author

I took the freedom to extend the commit message and to apply some cosmetic fixes. @notatallshaw please have a look.

All looks fine to me.

The packaging maintainers plan to deprecate mutability of packaging's
core objects to improve performance and hashability. Avoid mutating
the packaging.SpecifierSet object used to hold the requires-python
specifier when matching against the current Python version.
@dnicolodi
dnicolodi force-pushed the fix/prerelease-interpreter-check-20261019 branch from 9e80bd1 to 412e962 Compare November 3, 2026 20:28
@dnicolodi

Copy link
Copy Markdown
Member

Thanks @notatallshaw

@dnicolodi
dnicolodi merged commit bb6cabf into mesonbuild:main Nov 4, 2026
39 checks passed
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