Skip to content

chore: minor cleanups and perf tweaks from code review#2910

Open
henryiii wants to merge 1 commit into
pypa:mainfrom
henryiii:chore/review-cleanups
Open

chore: minor cleanups and perf tweaks from code review#2910
henryiii wants to merge 1 commit into
pypa:mainfrom
henryiii:chore/review-cleanups

Conversation

@henryiii

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖

This PR addresses items 5-9 from the code review checklist in #2908 with five small cleanup/perf fixes:

  • Streaming SHA-256 verification (util/file.py, util/python_build_standalone.py): Replace hashlib.sha256(path.read_bytes()).hexdigest() with hashlib.file_digest(f, "sha256").hexdigest() to avoid loading entire archives (potentially hundreds of MB) into memory at once. hashlib.file_digest was added in Python 3.11.0, which is the minimum supported version.

  • functools.cached_property for Logger.colors / Logger.symbols (logger.py): The Colors and Symbols objects were reconstructed on every property access, but colors_enabled and unicode_enabled never change after __init__. Converting to cached_property avoids the repeated allocations.

  • Remove redundant .strip() (platforms/windows.py): where_pip was already .strip()-ed at assignment (line 329); the duplicate call on line 331 was dead code.

  • Remove unreachable python_base_dir.exists() guard (util/python_build_standalone.py): Both callers of create_python_build_standalone_environment pass a fresh temp subdirectory, so the guard can never trip. Verified by inspecting pyodide.py (passes tmp / "base") and android.py (passes a newly mkdir-ed build_path).

  • Comment explaining the getattr shim (util/file.py): Notes why the shim is needed (Python 3.11.0-3.11.3 support) and what the cleanup looks like once the minimum is raised to 3.11.4+/3.12.

Part of #2908

🤖 Generated with Claude Code

- util/file.py, util/python_build_standalone.py: use hashlib.file_digest
  for streaming SHA-256 verification instead of loading whole archives
  into memory with read_bytes()
- logger.py: convert colors/symbols properties to functools.cached_property
  so the Colors/Symbols objects are constructed only once per Logger instance
- platforms/windows.py: remove redundant .strip() on where_pip (already
  stripped at assignment)
- util/python_build_standalone.py: remove unreachable python_base_dir.exists()
  guard (callers always pass a fresh temp subdirectory)
- util/file.py: add comment explaining the getattr shim for
  tar_.extraction_filter and when it can be removed

Assisted-by: ClaudeCode:claude-fable-5
@henryiii henryiii marked this pull request as ready for review June 12, 2026 05:37
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.

1 participant