Accept a major-only python_version such as "3" - #6688
Merged
matteius merged 2 commits intoJul 30, 2026
Conversation
The Pipfile [requires] section documents "3" as a valid python_version, but the version check compared the major AND minor components whenever fewer than three were given. "3" parses to 3.0, so every 3.x interpreter except 3.0 was reported as a mismatch, producing a spurious warning on install and a fatal DeployException under --deploy. Compare only the components actually given: major alone for "3", major and minor for "3.13", and an exact match for a full "3.13.1". The existing PEP 440 specifier path is untouched. Closes pypa#6687
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect Python version compatibility checks when python_version in the Pipfile [requires] section is specified as a major-only version like "3", aligning behavior with documented support and preventing spurious mismatch warnings / DeployException failures under --deploy.
Changes:
- Update
_python_version_matches_required()to compare only the components explicitly provided ("3"→ major-only,"3.13"→ major+minor,"3.13.1"→ exact). - Extend unit tests to cover major-only
python_versionrequirements (including non-3 majors). - Add a
news/bugfix entry describing the regression and fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
pipenv/utils/project.py |
Adjusts version-matching logic to handle major-only requirements correctly. |
tests/unit/test_utils.py |
Adds regression tests validating major-only version matching behavior. |
news/6687.bugfix.rst |
Documents the restored support and user-facing impact. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #6687.
python_version = "3"in the Pipfile[requires]section — which the docs list as valid — produced a spurious mismatch warning on install and a fatalDeployExceptionunder--deploy._python_version_matches_requiredbranches on how many components the requirement has, but only distinguished "3 or more" from "everything else":"3"has one component, so it took the second branch — andparse_version("3")fills in a zero minor, so the comparison becameactual.minor == 0. Every 3.x interpreter except 3.0 was rejected:Change
Compare only the components actually given:
"3""3.13""3.13.1"The PEP 440 specifier path (
">=3.9",">=3.9,<4") is untouched.Tests
TestPythonVersionMatchesRequiredalready has a parametrized table, so the major-only cases go in alongside the existing #6514 substring-regression rows:3.13.14/3.9.1/3.0.0/3.11all satisfy"3", while2.7.18and4.0.0don't, plus2.7.18against"2"so the rule isn't special-cased to Python 3.Reverting only
pipenv/fails exactly the new rows and nothing else:Verification
pytest tests/unit/test_utils.py -k PythonVersionMatchesRequired→ 26 passedpytest tests/unit/test_utils.py→ 210 passed, 5 skipped (skips are POSIX-only path tests, I'm on Windows)ruff checkon both changed files → all checks passednews/6687.bugfix.rstOne note:
ruff format --checkreports both changed files as needing reformatting, but that's pre-existing on a clean tree (verified by stashing), so I left it alone rather than mixing unrelated reformatting into this diff.