-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix Python3.10/3.11 tomli compatibility #6449
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
Conversation
Add 'from __future__ import annotations' to files in pipenv/patched/pip that use Python 3.10+ type annotation syntax (dict | None, list[str]). This allows the code to work on Python 3.9 by deferring annotation evaluation (PEP 563). Fixes #6448
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes Python 3.9 compatibility issues that occur when pipenv is installed via pipx under Python 3.12+ and used to manage Python 3.9 projects. The fix involves two main changes:
- Corrects tomli import statements to use direct
importinstead offrom ... import ... assyntax, which the vendoring script doesn't handle properly - Adds
from __future__ import annotationsto 26 files that use Python 3.10+ type annotation syntax (e.g.,dict | None,list[str]), enabling PEP 563 postponed evaluation to prevent runtime errors in Python 3.9
Reviewed changes
Copilot reviewed 27 out of 30 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
pipenv/vendor/pipenv.patched.pip/_vendor/dependency_groups/_toml_compat.py |
Changes tomli import from from ... import ... as to direct import for vendoring compatibility |
pipenv/vendor/pipenv.patched.pip/_internal/utils/compat.py |
Changes tomli import from from ... import ... as to direct import for vendoring compatibility |
pipenv/patched/pip/_vendor/truststore/_windows.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_vendor/truststore/_openssl.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_vendor/truststore/_macos.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_vendor/truststore/_api.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/utils/wheel.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/utils/filetypes.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/utils/appdirs.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/resolution/base.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/req/req_set.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/req/req_dependency_group.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/network/xmlrpc.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/network/utils.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/models/search_scope.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/models/installation_report.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/commands/wheel.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/commands/uninstall.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/commands/lock.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/commands/inspect.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/commands/help.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/commands/hash.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/commands/freeze.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/commands/download.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/commands/completion.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/commands/check.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
pipenv/patched/pip/_internal/commands/cache.py |
Adds from __future__ import annotations for Python 3.9 compatibility |
news/6448.bugfix.rst |
Adds release note documenting the Python 3.9 compatibility fix |
Pipfile.lock |
Updates lock file with new dependency versions and hashes |
Pipfile |
Updates dev dependencies including pypiserver, tomli, bottle, and legacy-cgi |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Secondary Fix (Note: python3.9 support WILL be dropped after this).
Fix
TypeError: unsupported operand type(s) for |: 'types.GenericAlias' and 'NoneType'when using pipenv with Python 3.9 target environments.Stop gap because I missed removing 3.9 from the pyproject.toml before publishing the last release.
The Problem
When pipenv is installed via pipx under Python 3.12 and used to manage a Python 3.9 project, importing files from
pipenv/patched/pipfails because they use Python 3.10+ type annotation syntax (dict | None,list[str]) which is not valid at runtime in Python 3.9.Example error from issue #6448:
The Fix
Add
from __future__ import annotationsto all affected files inpipenv/patched/pip. This enables PEP 563 (Postponed Evaluation of Annotations), which stores annotations as strings rather than evaluating them at import time, allowing the modern type syntax to work on Python 3.9+.Files Modified (26 files)
Commands:
pipenv/patched/pip/_internal/commands/cache.pypipenv/patched/pip/_internal/commands/check.pypipenv/patched/pip/_internal/commands/completion.pypipenv/patched/pip/_internal/commands/download.pypipenv/patched/pip/_internal/commands/freeze.pypipenv/patched/pip/_internal/commands/hash.pypipenv/patched/pip/_internal/commands/help.pypipenv/patched/pip/_internal/commands/inspect.pypipenv/patched/pip/_internal/commands/lock.pypipenv/patched/pip/_internal/commands/uninstall.pypipenv/patched/pip/_internal/commands/wheel.pyModels:
pipenv/patched/pip/_internal/models/installation_report.pypipenv/patched/pip/_internal/models/search_scope.py(file from the original error)Network:
pipenv/patched/pip/_internal/network/utils.pypipenv/patched/pip/_internal/network/xmlrpc.pyReq:
pipenv/patched/pip/_internal/req/req_dependency_group.pypipenv/patched/pip/_internal/req/req_set.pyResolution:
pipenv/patched/pip/_internal/resolution/base.pyUtils:
pipenv/patched/pip/_internal/utils/appdirs.pypipenv/patched/pip/_internal/utils/filetypes.pypipenv/patched/pip/_internal/utils/wheel.pyVendor (truststore):
pipenv/patched/pip/_vendor/truststore/_api.pypipenv/patched/pip/_vendor/truststore/_macos.pypipenv/patched/pip/_vendor/truststore/_openssl.pypipenv/patched/pip/_vendor/truststore/_windows.pyFixes #6448
The checklist
news/directory to describe this fix with the extension.bugfix.rstPull Request opened by Augment Code with guidance from the PR author