Skip to content

Conversation

@matteius
Copy link
Member

@matteius matteius commented Dec 7, 2025

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/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
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