Skip to content

Conversation

@matteius
Copy link
Member

@matteius matteius commented Dec 7, 2025

Summary

  • The vendoring script doesn't like imports that import something as something else, and it broke imports for python 3.10/3.11.

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/pip fails 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:

File "...pipenv/patched/pip/_internal/models/search_scope.py", line 26, in SearchScope
    index_lookup: dict | None = None
TypeError: unsupported operand type(s) for |: 'types.GenericAlias' and 'NoneType'

The Fix

Add from __future__ import annotations to all affected files in pipenv/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.py
  • pipenv/patched/pip/_internal/commands/check.py
  • pipenv/patched/pip/_internal/commands/completion.py
  • pipenv/patched/pip/_internal/commands/download.py
  • pipenv/patched/pip/_internal/commands/freeze.py
  • pipenv/patched/pip/_internal/commands/hash.py
  • pipenv/patched/pip/_internal/commands/help.py
  • pipenv/patched/pip/_internal/commands/inspect.py
  • pipenv/patched/pip/_internal/commands/lock.py
  • pipenv/patched/pip/_internal/commands/uninstall.py
  • pipenv/patched/pip/_internal/commands/wheel.py

Models:

  • pipenv/patched/pip/_internal/models/installation_report.py
  • pipenv/patched/pip/_internal/models/search_scope.py (file from the original error)

Network:

  • pipenv/patched/pip/_internal/network/utils.py
  • pipenv/patched/pip/_internal/network/xmlrpc.py

Req:

  • pipenv/patched/pip/_internal/req/req_dependency_group.py
  • pipenv/patched/pip/_internal/req/req_set.py

Resolution:

  • pipenv/patched/pip/_internal/resolution/base.py

Utils:

  • pipenv/patched/pip/_internal/utils/appdirs.py
  • pipenv/patched/pip/_internal/utils/filetypes.py
  • pipenv/patched/pip/_internal/utils/wheel.py

Vendor (truststore):

  • pipenv/patched/pip/_vendor/truststore/_api.py
  • pipenv/patched/pip/_vendor/truststore/_macos.py
  • pipenv/patched/pip/_vendor/truststore/_openssl.py
  • pipenv/patched/pip/_vendor/truststore/_windows.py

Fixes #6448

The checklist

  • Associated issue
  • A news fragment in the news/ directory to describe this fix with the extension .bugfix.rst

Pull Request opened by Augment Code with guidance from the PR author

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
@matteius matteius changed the title Fix Python 3.9 compatibility by adding future annotations Fix Python3.10/3.11 tomli compatibility Dec 9, 2025
@matteius matteius requested review from Copilot and oz123 December 9, 2025 10:48
Copy link
Contributor

Copilot AI left a 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 import instead of from ... import ... as syntax, which the vendoring script doesn't handle properly
  • Adds from __future__ import annotations to 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.

@matteius matteius merged commit b8e5110 into main Dec 9, 2025
25 of 26 checks passed
@matteius matteius deleted the fix/python39-type-annotations-compatibility branch December 9, 2025 10:59
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.

search_scope.py breaks possibly because of Python 3.9 vs. 3.14 compatibility changes

2 participants