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>
This commit is contained in:
Dharshini_RS
2026-09-13 09:25:21 +02:00
committed by GitHub
co-authored by Christian Clauss pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
parent 7b5e704d9f
commit aa38af81c9
3 changed files with 123 additions and 4 deletions
@@ -103,9 +103,9 @@ class LinkedList:
def partition_liked_list(self, value: int) -> None:
"""
Partition Linked List based on node elements in-order.
All nodes with elements less than value should occur in the left,
while those greater than to value, in the right.
Partition the linked list based on node elements in order.
All nodes with elements less than value should occur on the left,
while those greater than or equal to value should occur on the right.
>>> linked_list = LinkedList()
>>> linked_list.add(1)
@@ -156,7 +156,7 @@ class LinkedList:
1
"""
if self.head is None:
return None
return
less_nodes, greater_nodes = Node(0), Node(0)
current, current_less, current_greater = self.head, less_nodes, greater_nodes
+115
View File
@@ -0,0 +1,115 @@
#!/usr/bin/env python3
"""
pr_file_map.py
Lists all open pull requests in the current directory's git repo (via `gh`)
and, for each file touched by any open PR, which PR number(s) touch it.
Output is GitHub-flavored Markdown: a sorted list of files that currently
exist in the working directory, each with its modifying PR numbers, followed
by a separate section for files referenced by open PRs but that do not exist
in the working directory (e.g. deleted, renamed, or on a branch not checked
out locally).
Requirements: gh (GitHub CLI), authenticated (`gh auth login`)
Usage:
./pr_file_map.py
./pr_file_map.py > report.md
"""
import json
import os
import shutil
import subprocess
import sys
from collections import defaultdict
def run_gh(args: list[str]) -> str:
try:
result = subprocess.run( # noqa: S603
["gh", *args], # noqa: S607
capture_output=True,
text=True,
check=True,
)
except FileNotFoundError:
sys.exit("Error: 'gh' (GitHub CLI) is not installed or not in PATH.")
except subprocess.CalledProcessError as e:
sys.exit(f"Error running 'gh {' '.join(args)}':\n{e.stderr.strip()}")
return result.stdout
def check_gh_auth() -> None:
try:
subprocess.run(
["gh", "auth", "status"], # noqa: S607
capture_output=True,
text=True,
check=True,
)
except subprocess.CalledProcessError:
sys.exit("Error: gh is not authenticated. Run 'gh auth login' first.")
def get_open_prs() -> list[dict]:
raw = run_gh(
["pr", "list", "--state", "open", "--limit", "1000", "--json", "number,title"]
)
return json.loads(raw)
def get_pr_files(pr_number: int) -> list[str]:
raw = run_gh(["pr", "view", str(pr_number), "--json", "files"])
data = json.loads(raw)
return [f["path"] for f in data.get("files", [])]
def main() -> None:
if shutil.which("gh") is None:
sys.exit("Error: 'gh' (GitHub CLI) is not installed or not in PATH.")
check_gh_auth()
prs = get_open_prs()
if not prs:
print("No open pull requests found.")
return
file_to_prs: dict[str, list[int]] = defaultdict(list)
for pr in prs:
pr_number = pr["number"]
for path in get_pr_files(pr_number):
file_to_prs[path].append(pr_number)
existing: dict[str, list[int]] = {}
missing: dict[str, list[int]] = {}
for path, pr_numbers in file_to_prs.items():
target = existing if os.path.exists(path) else missing
target[path] = sorted(set(pr_numbers))
# --- Render GitHub-flavored Markdown ---
print("# Open Pull Request File Map\n")
print("## Existing files\n")
if existing:
for path in sorted(existing):
pr_list = " ".join(f"#{n}" for n in existing[path])
print(f"- `{path}`: {pr_list}")
else:
print("_None._")
print("\n## Files not present in the working directory\n")
if missing:
for path in sorted(missing):
pr_list = " ".join(f"#{n}" for n in missing[path])
print(f"- `{path}`: {pr_list}")
else:
print("_None._")
if __name__ == "__main__":
main()
+4
View File
@@ -77,6 +77,10 @@ def bucket_sort(
>>> data = [9, 2, 7, 1, 5]
>>> bucket_sort(data) == sorted(data)
True
>>> bucket_sort(data, 3.5)
Traceback (most recent call last):
...
TypeError: bucket_count must be an integer
"""
if not isinstance(bucket_count, int):