Skip to content

Add support for '3.7.*' == python_full_version-style markers#18974

Open
charliermarsh wants to merge 1 commit intomainfrom
charlie/star
Open

Add support for '3.7.*' == python_full_version-style markers#18974
charliermarsh wants to merge 1 commit intomainfrom
charlie/star

Conversation

@charliermarsh
Copy link
Copy Markdown
Member

Summary

There's a comment here that suggests these aren't valid per PEP 440, but I think these are valid?

See: pypa/packaging#1126.

@charliermarsh charliermarsh added the bug Something isn't working label Apr 12, 2026
@charliermarsh charliermarsh marked this pull request as ready for review April 12, 2026 10:57
@konstin
Copy link
Copy Markdown
Member

konstin commented Apr 12, 2026

I wouldn't support this, my read is that PEP 440 is directional (e.g. with ~=), in the sense that it's <version> <op> <version-or-version-expression-for-op> and .* is only supported on the RHS. If we were to treat as largely commutative, we'd get also get expressions such as "3.8.*" == "3.*"

@charliermarsh
Copy link
Copy Markdown
Member Author

I disagree because == is commutative. I think '3.7.*' == python_full_version should work, but '3.7.*' ~= python_full_version should not.

@charliermarsh
Copy link
Copy Markdown
Member Author

(I don't think this requires us to support "3.8.*" == "3.*"? We can just reject that. You can't have a pattern on both sides of the operator.)

@konstin
Copy link
Copy Markdown
Member

konstin commented Apr 12, 2026

PEP 440 is mathematically strange is the sense that == is not actually the equality operator. In '3.8.1' == '3.8.*' and '3.8.1' == '3.8.1.*', the elements do not form an equivalence class. In a sense, the operator is == .* with two versions as parameters. As I read https://packaging.python.org/en/latest/specifications/version-specifiers/#version-matching, it intends to specify clauses in the form == <version>[.*], it doesn't have an examples of <version>.* on the LHS, hence the comment about this isn't supported.

By limiting the LHS to versions and keeping clauses to operator and RHS, we IMHO exclude a good chunk of additional complexity without additional use cases in the already complex PEP 508 logic.

@charliermarsh
Copy link
Copy Markdown
Member Author

But <version> == <version> is not even something that's covered by PEP 440, is it? In PEP 440, everything is an operator followed by a version. We are referring here to PEP 508 which has its own grammar and its own semantics, and I don't really see how this isn't allowed by PEP 508, personally. It seems easy to support given that we already support it for other operators.

@charliermarsh
Copy link
Copy Markdown
Member Author

Do you think we should instead be rejecting all markers with versions on the LHS regardless of operator?

@konstin
Copy link
Copy Markdown
Member

konstin commented Apr 14, 2026

I have some split thoughts about this:

On one hand, this change doesn't add any new capabilities: You can (and many do) already use python_full_version == '3.7.*', and there's no reason to do it the other way. PEP 508 is a bit vague in what it wants semantically, but from the PEP 440 examples I'd argue it's against the spirit of PEP 440, which is read as defining <version> <clause> -> <version> <op> <version-op> operations. (While following the old implementation of PEP 508, python_full_version == python_full_version and '3.7' == '3.7' are in the spirit of PEP 508 because they are PEP 440-evaluatable after substitution, but you see how we're getting into the gaps of the text here, where it shows that the text was written after the implementation, not the other way round.)

Otoh, this is a simple change. It doesn't add much burden, for our implementation at least, and I can't really block this change on that basis.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants