Skip to content

Commit aa38af8

Browse files
Dharshini-RS03cclausspre-commit-ci[bot]
authored
fix:bucket count type (#15063)
* fix:bucket count type * fixed TypeError * Refine docstring and adjust return statement Updated docstring for partition_liked_list method to clarify behavior. Changed return statement from None to None for consistency. * Add script to map open PRs to modified files This script lists all open pull requests in the current directory's git repository and maps each file touched by any open PR to its corresponding PR numbers. It outputs the results in GitHub-flavored Markdown format. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add noqa comments for subprocess calls Add noqa comments to suppress specific linting warnings. --------- Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 7b5e704 commit aa38af8

3 files changed

Lines changed: 123 additions & 4 deletions

File tree

data_structures/linked_list/partition_linked_list.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ def add(self, item: Any, position: int = 0) -> None:
103103

104104
def partition_liked_list(self, value: int) -> None:
105105
"""
106-
Partition Linked List based on node elements in-order.
107-
All nodes with elements less than value should occur in the left,
108-
while those greater than to value, in the right.
106+
Partition the linked list based on node elements in order.
107+
All nodes with elements less than value should occur on the left,
108+
while those greater than or equal to value should occur on the right.
109109
110110
>>> linked_list = LinkedList()
111111
>>> linked_list.add(1)
@@ -156,7 +156,7 @@ def partition_liked_list(self, value: int) -> None:
156156
1
157157
"""
158158
if self.head is None:
159-
return None
159+
return
160160

161161
less_nodes, greater_nodes = Node(0), Node(0)
162162
current, current_less, current_greater = self.head, less_nodes, greater_nodes

scripts/pr_file_map.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/usr/bin/env python3
2+
"""
3+
pr_file_map.py
4+
5+
Lists all open pull requests in the current directory's git repo (via `gh`)
6+
and, for each file touched by any open PR, which PR number(s) touch it.
7+
8+
Output is GitHub-flavored Markdown: a sorted list of files that currently
9+
exist in the working directory, each with its modifying PR numbers, followed
10+
by a separate section for files referenced by open PRs but that do not exist
11+
in the working directory (e.g. deleted, renamed, or on a branch not checked
12+
out locally).
13+
14+
Requirements: gh (GitHub CLI), authenticated (`gh auth login`)
15+
16+
Usage:
17+
./pr_file_map.py
18+
./pr_file_map.py > report.md
19+
"""
20+
21+
import json
22+
import os
23+
import shutil
24+
import subprocess
25+
import sys
26+
from collections import defaultdict
27+
28+
29+
def run_gh(args: list[str]) -> str:
30+
try:
31+
result = subprocess.run( # noqa: S603
32+
["gh", *args], # noqa: S607
33+
capture_output=True,
34+
text=True,
35+
check=True,
36+
)
37+
except FileNotFoundError:
38+
sys.exit("Error: 'gh' (GitHub CLI) is not installed or not in PATH.")
39+
except subprocess.CalledProcessError as e:
40+
sys.exit(f"Error running 'gh {' '.join(args)}':\n{e.stderr.strip()}")
41+
return result.stdout
42+
43+
44+
def check_gh_auth() -> None:
45+
try:
46+
subprocess.run(
47+
["gh", "auth", "status"], # noqa: S607
48+
capture_output=True,
49+
text=True,
50+
check=True,
51+
)
52+
except subprocess.CalledProcessError:
53+
sys.exit("Error: gh is not authenticated. Run 'gh auth login' first.")
54+
55+
56+
def get_open_prs() -> list[dict]:
57+
raw = run_gh(
58+
["pr", "list", "--state", "open", "--limit", "1000", "--json", "number,title"]
59+
)
60+
return json.loads(raw)
61+
62+
63+
def get_pr_files(pr_number: int) -> list[str]:
64+
raw = run_gh(["pr", "view", str(pr_number), "--json", "files"])
65+
data = json.loads(raw)
66+
return [f["path"] for f in data.get("files", [])]
67+
68+
69+
def main() -> None:
70+
if shutil.which("gh") is None:
71+
sys.exit("Error: 'gh' (GitHub CLI) is not installed or not in PATH.")
72+
73+
check_gh_auth()
74+
75+
prs = get_open_prs()
76+
if not prs:
77+
print("No open pull requests found.")
78+
return
79+
80+
file_to_prs: dict[str, list[int]] = defaultdict(list)
81+
82+
for pr in prs:
83+
pr_number = pr["number"]
84+
for path in get_pr_files(pr_number):
85+
file_to_prs[path].append(pr_number)
86+
87+
existing: dict[str, list[int]] = {}
88+
missing: dict[str, list[int]] = {}
89+
90+
for path, pr_numbers in file_to_prs.items():
91+
target = existing if os.path.exists(path) else missing
92+
target[path] = sorted(set(pr_numbers))
93+
94+
# --- Render GitHub-flavored Markdown ---
95+
print("# Open Pull Request File Map\n")
96+
97+
print("## Existing files\n")
98+
if existing:
99+
for path in sorted(existing):
100+
pr_list = " ".join(f"#{n}" for n in existing[path])
101+
print(f"- `{path}`: {pr_list}")
102+
else:
103+
print("_None._")
104+
105+
print("\n## Files not present in the working directory\n")
106+
if missing:
107+
for path in sorted(missing):
108+
pr_list = " ".join(f"#{n}" for n in missing[path])
109+
print(f"- `{path}`: {pr_list}")
110+
else:
111+
print("_None._")
112+
113+
114+
if __name__ == "__main__":
115+
main()

sorts/bucket_sort.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ def bucket_sort(
7777
>>> data = [9, 2, 7, 1, 5]
7878
>>> bucket_sort(data) == sorted(data)
7979
True
80+
>>> bucket_sort(data, 3.5)
81+
Traceback (most recent call last):
82+
...
83+
TypeError: bucket_count must be an integer
8084
"""
8185

8286
if not isinstance(bucket_count, int):

0 commit comments

Comments
 (0)