Fix Python 3.9 compatibility by adding future annotations #6449
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
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