Skip to content

gh-146310: Fix ensurepip to treat empty WHEEL_PKG_DIR as unset#146357

Open
kimimgo wants to merge 1 commit intopython:mainfrom
kimimgo:fix/ensurepip-empty-wheel-pkg-dir-146310
Open

gh-146310: Fix ensurepip to treat empty WHEEL_PKG_DIR as unset#146357
kimimgo wants to merge 1 commit intopython:mainfrom
kimimgo:fix/ensurepip-empty-wheel-pkg-dir-146310

Conversation

@kimimgo
Copy link

@kimimgo kimimgo commented Mar 24, 2026

Fixes #146310

Path('') resolves to the current working directory (PosixPath('.')), so when WHEEL_PKG_DIR is an empty string (not None), ensurepip searches CWD for wheel files. This can cause unexpected behavior or crashes if CWD contains files matching pip-*.whl.

Changes

  • Lib/ensurepip/__init__.py: Add truthiness check so empty strings are treated the same as None
  • Lib/test/test_ensurepip.py: Add test verifying empty WHEEL_PKG_DIR does not search CWD

Before/After

# Before: Path('').resolve() -> PosixPath('/current/working/dir')
# Empty string was treated as a valid directory path

# After: Empty string treated as None -> use bundled wheel

Path('') resolves to CWD, so an empty WHEEL_PKG_DIR string caused
ensurepip to search the current working directory for wheel files.
Add a truthiness check to treat empty strings the same as None.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ensurepip looks for wheels in CWD when WHEEL_PKG_DIR is an empty string

1 participant