← Back to Pull requests

Fix `pip list --exclude` making `--not-required` list dependencies #14130

Merged
2ykwang merged 3 files (39 lines) on Jul 02, 2026 22:54 UTC
View on GitHub
2ykwang 2ykwang commented on Jul 01, 2026 13:35 UTC
Author

<!---
Thank you for your soon to be pull request. Before you submit this, please
double check to make sure that you've added a news file fragment. In pip we
generate our NEWS.rst from multiple news fragment files, and all pull requests
require either a news file fragment or a marker to indicate they don't require
one.

To read more about adding a news file fragment for your PR, please check out
our documentation at: https://pip.pypa.io/en/latest/development/contributing/#news-entries
-->

Closes #14129.

Moved the --exclude filter after get_not_required so excluded packages no longer drop their dependencies into the top-level listing.

Diff: 39 lines (+34 / -5) across 3 files Reviewer: sepehr-rs Review duration: 1998m
All Vouch review confidence checks passed
Residual risk 0.02 = Change Risk (0.28) × (1 − Review Confidence (0.92)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.28 · 39 lines diff across 3 files
0.28
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.92 · 4 substantive comment(s)
0.92
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
91%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.221
Real PR Conversation Timeline
7 items
sepehr-rs sepehr-rs commented on code on Jul 02, 2026 06:20 UTC
Code Review
tests/functional/test_list.py:1
@@ -660,6 +660,33 @@ def test_not_required_flag(script: PipTestEnvironment, data: TestData) -> None:
     assert "TopoRequires3 " not in result.stdout
 
 
+def test_not_required_with_exclude_does_not_list_dependencies(
+    script: PipTestEnvironment, data: TestData
+) -> None:
+    script.pip(
+        "install",
+        "--no-build-isolation",
+        "-f",
+        data.find_links,
+        "--no-index",
+        "TopoRequires4",
+    )
+
+    result = script.pip(
+        "list",
+        "--not-required",
+        "--exclude",
+        "TopoRequires4",
+        "--format=json",
+        expect_stderr=True,

Is expect_stderr=True needed here? The test passes without it as well. Unless there is a reason to keep, I think we can drop it. What do you think?

sepehr-rs sepehr-rs approved these changes on Jul 02, 2026 06:22 UTC
Approved Reviewer

Hi @2ykwang, thanks for your contribution!
I've left a small nitpick on the test you added, but besides that LGTM from me.
Thanks again!

2ykwang 2ykwang commented on code on Jul 02, 2026 11:17 UTC
Code Review
tests/functional/test_list.py:1
@@ -660,6 +660,33 @@ def test_not_required_flag(script: PipTestEnvironment, data: TestData) -> None:
     assert "TopoRequires3 " not in result.stdout
 
 
+def test_not_required_with_exclude_does_not_list_dependencies(
+    script: PipTestEnvironment, data: TestData
+) -> None:
+    script.pip(
+        "install",
+        "--no-build-isolation",
+        "-f",
+        data.find_links,
+        "--no-index",
+        "TopoRequires4",
+    )
+
+    result = script.pip(
+        "list",
+        "--not-required",
+        "--exclude",
+        "TopoRequires4",
+        "--format=json",
+        expect_stderr=True,

yeah, makes sense. thanks for catching this @sepehr-rs!

2ykwang 2ykwang commented on code on Jul 02, 2026 11:22 UTC
Code Review
tests/functional/test_list.py:1
@@ -660,6 +660,33 @@ def test_not_required_flag(script: PipTestEnvironment, data: TestData) -> None:
     assert "TopoRequires3 " not in result.stdout
 
 
+def test_not_required_with_exclude_does_not_list_dependencies(
+    script: PipTestEnvironment, data: TestData
+) -> None:
+    script.pip(
+        "install",
+        "--no-build-isolation",
+        "-f",
+        data.find_links,
+        "--no-index",
+        "TopoRequires4",
+    )
+
+    result = script.pip(
+        "list",
+        "--not-required",
+        "--exclude",
+        "TopoRequires4",
+        "--format=json",
+        expect_stderr=True,

also, a few other pip list tests have the same expect_stderr=True, out of scope here, will look separately. @sepehr-rs

sepehr-rs sepehr-rs commented on code on Jul 02, 2026 11:27 UTC
Code Review
tests/functional/test_list.py:1
@@ -660,6 +660,33 @@ def test_not_required_flag(script: PipTestEnvironment, data: TestData) -> None:
     assert "TopoRequires3 " not in result.stdout
 
 
+def test_not_required_with_exclude_does_not_list_dependencies(
+    script: PipTestEnvironment, data: TestData
+) -> None:
+    script.pip(
+        "install",
+        "--no-build-isolation",
+        "-f",
+        data.find_links,
+        "--no-index",
+        "TopoRequires4",
+    )
+
+    result = script.pip(
+        "list",
+        "--not-required",
+        "--exclude",
+        "TopoRequires4",
+        "--format=json",
+        expect_stderr=True,

Yes, I noticed those as well. I think they can go in a separate cleanup PR. Thanks for checking, though!

ichard26 ichard26 approved these changes on Jul 02, 2026 18:31 UTC
Approved Reviewer

Thank you!

Reviewers
Assignees
2ykwang 2ykwang
Labels
risk: low confidence: 91.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 28.0% (LOW) · Higher = larger blast radius
28.0%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 91.7% · Lower = rushed or shallow review
91.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 2.3% · Safe to merge
2.3%
Repository