Skip to content

Commit 9919d65

Browse files
authored
Merge branch 'master' into fix-invalid-parameter-default
2 parents 52198c6 + b6224ec commit 9919d65

120 files changed

Lines changed: 6648 additions & 1054 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.devcontainer/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ This is **Devcontainer** configuration to provide a consistent development envir
1313

1414
## Usage
1515

16-
1. Install [**Docker** ](https://www.docker.com/get-started/) and [**Visual Studio Code**](https://code.visualstudio.com/)
16+
1. Install [**Docker**](https://www.docker.com/get-started/) and [**Visual Studio Code**](https://code.visualstudio.com/)
1717
2. Install the **Remote - Containers** extension in VS Code
1818

1919
- Do `CTRL+P`, paste this command and press `Enter`
2020

2121
```shell
2222
ext install ms-vscode-remote.remote-containers
2323
```
24+
2425
3. Open this repository in VS Code
2526
4. When prompted, click **"Reopen in Container"**
2627
5. Wait for the environment to build and initialize

.github/dependabot.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ updates:
66
directory: "/"
77
schedule:
88
interval: "daily"
9+
cooldown:
10+
default-days: 7

.github/pull_request_template.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
### Describe your change:
2-
3-
1+
### Describe your change
42

53
* [ ] Add an algorithm?
64
* [ ] Fix a bug or typo in an existing algorithm?
75
* [ ] Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
86
* [ ] Documentation change?
97

10-
### Checklist:
8+
### Checklist
9+
1110
* [ ] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md).
1211
* [ ] This pull request is all my own work -- I have not plagiarized.
1312
* [ ] I know that pull requests will not be merged if they fail the automated tests.
14-
* [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
13+
* [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
1514
* [ ] All new Python files are placed inside an existing directory.
1615
* [ ] All filenames are in all lowercase characters with no spaces or dashes.
1716
* [ ] All functions and variable names follow Python naming conventions.
1817
* [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html).
1918
* [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing.
2019
* [ ] All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
21-
* [ ] If this pull request resolves one or more open issues then the description above includes the issue number(s) with a [closing keyword](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue): "Fixes #ISSUE-NUMBER".
20+
* [ ] If this pull request resolves one or more open issues, then the description above includes the issue number(s) with a [closing keyword](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue): "Fixes #ISSUE-NUMBER".

.github/skills/code-review/SKILL.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,32 @@ suggest the fix — never just "rejected".
3333
- [ ] Descriptive variable and function names (no single letters where a word helps).
3434
- [ ] Code is formatted and lint-clean (`ruff`, `pre-commit`).
3535

36+
> **Optional hint:** When a PR hand-writes a simple class that is mostly a
37+
> bundle of fields (a manual `__init__` plus `__repr__`/`__eq__`), it is worth
38+
> **suggesting** `from typing import NamedTuple` or
39+
> `from dataclasses import dataclass` where they would simplify the code. These
40+
> are underutilized tools that our contributors would benefit from using where
41+
> they make sense. Offer it as an optional improvement, not a blocker — do not
42+
> request changes solely because a class was written the longhand way.
43+
44+
#### When a PR fails `ruff check`
45+
46+
Don't just report the failure — try the mechanical fixes and recommend the one
47+
that works, in this order:
48+
49+
1. Run `ruff check --fix file_path.py`. If that makes the file pass, recommend
50+
that solution — these are the fixes `ruff` considers **safe**.
51+
2. If it still fails, run `ruff check --fix --unsafe-fixes file_path.py`. If that
52+
makes the file pass **and** the resulting diff is genuinely safe (it preserves
53+
behavior — review it, don't trust it blindly), recommend that solution and note
54+
that it required `--unsafe-fixes`.
55+
3. If neither passes, or the unsafe fix would change behavior, describe the
56+
remaining rule violations and the manual change the author needs to make.
57+
58+
Always quote the exact rule code(s) `ruff` reports (e.g., `ruff rule UP047`,
59+
`ruff rule RUF100`) so the author can run those commands to read the rules being
60+
flagged. Also, paste the concrete command you ran.
61+
3662
### 3. Other Requirements for Submissions
3763

3864
- [ ] At least one **Wikipedia (or equivalent) URL** documenting the algorithm.
@@ -43,7 +69,7 @@ suggest the fix — never just "rejected".
4369

4470
Emit exactly these headings so reviews are comparable and easy to automate:
4571

46-
```
72+
```text
4773
### Is this an algorithm? — <yes/no + one-line why>
4874
### Duplicate / prior-art check — <#NNNN | none found>
4975
### Coding style — <pass | issues: …>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Skill: New pull request for TheAlgorithms/Python
2+
3+
Create a new pull request using the rules already written in
4+
[`CONTRIBUTING.md`](../../../CONTRIBUTING.md). The goal is that creating a new
5+
pull request (human or AI) can run the same way every time, and that produces a
6+
clear, kind, tested, type-hinted, mergeable contribution.
7+
8+
## How to run this skill
9+
10+
Make sure that the local `master` branch is synced with `upstream/master` before
11+
creating a new pull request.
12+
13+
Create a new clearly named branch for the pull request. Pull request changes must
14+
not be made or submitted on the `master` branch.
15+
16+
Never hand-edit or revert the `uv.lock` file. If you add a legitimate
17+
dependency, let the `uv-lock` pre-commit hook regenerate it — do not touch it by
18+
hand. A hand-modified `uv.lock` makes the `algorithms-keeper` bot close the pull
19+
request as invalid, and even a repo maintainer cannot undo that.
20+
21+
Always check at least one Markdown checkbox in the pull request description (the "Describe your change" section), or the
22+
`algorithms-keeper` bot will close the pull request as invalid — and it does
23+
this *before* a human reads the PR, so a genuinely good change gets closed for a
24+
formatting reason. This applies to **every** pull request, including CI, docs,
25+
and tooling changes that are not algorithms: tick the boxes that genuinely apply
26+
so the body is never submitted with all boxes empty. Any repo maintainer can
27+
undo this if you @mention them on the closed pull request, but re-opening is
28+
often unreliable, so it is far better to get it right the first time.
29+
30+
### 1. Before contributing / Is this an algorithm?
31+
32+
- [ ] The change adds, fixes, or documents **one algorithm** — not multiple, and
33+
not both code and doctest changes in the same PR.
34+
- [ ] It is a genuine algorithm or data structure (see the *What is an Algorithm?*
35+
section), not a script, snippet, how-to-use for an existing API, or exercise
36+
dump.
37+
- [ ] It is **not already in the repository** (search the existing directories).
38+
- [ ] **No earlier open PR** already does the same thing — link it if one exists.
39+
- [ ] Properly attributed — no plagiarism; prior sources credited.
40+
41+
### 2. Coding Style
42+
43+
- [ ] `from __future__ import annotations` is not needed because this repo only uses
44+
the latest version of CPython.
45+
- [ ] File and directory names are lowercase, use underscores, and land inside an
46+
existing directory.
47+
- [ ] Public functions/classes have **type hints**.
48+
- [ ] Public functions have **doctests that actually pass**.
49+
- [ ] Descriptive variable and function names (no single letters where a word helps).
50+
- [ ] For a simple class that is mostly a bundle of fields, **consider**
51+
`from typing import NamedTuple` or `from dataclasses import dataclass`
52+
instead of a hand-written `__init__`/`__repr__`/`__eq__`. These are
53+
underutilized tools that make simple classes shorter and clearer — use
54+
them where they genuinely simplify the code, not everywhere.
55+
- [ ] Code is formatted and lint-clean (`ruff`, `pre-commit`).
56+
- [ ] `DIRECTORY.md` and `README.md` are **not hand-edited** — the
57+
`algorithms-keeper` bot regenerates them automatically after merge.
58+
59+
### 3. Other Requirements for Submissions
60+
61+
- [ ] At least one **Wikipedia (or equivalent) URL** documenting the algorithm.
62+
- [ ] Docstring explains what the function does and its parameters/returns.
63+
- [ ] No unnecessary third-party dependencies.
64+
65+
## Before you click "Create pull request"
66+
67+
This is the final gate. Do not open the pull request until every item here is true:
68+
69+
- [ ] At least one Markdown checkbox in the PR description is checked. **Verify
70+
this by re-reading the rendered body** — if every box is still `- [ ]`, the
71+
`algorithms-keeper` bot will auto-close the PR before any human sees it.
72+
Check the boxes that genuinely apply to this change; never submit an
73+
all-empty checklist, even for a CI, docs, or tooling PR.
74+
- [ ] The branch is not `master`, and `master` is synced with `upstream/master`.
75+
- [ ] `uv.lock` was not hand-edited.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Skill: Review an open issue for TheAlgorithms/Python
2+
3+
Triage an open issue — most often one carrying the `bug` label — **together with
4+
every pull request attached to it**, and produce a verdict a maintainer can act on
5+
without re-doing the work. The goal is a review that any triager (human or AI) can
6+
run the same way every time, and that ends in an explicit list of `Closes #NNNNN`
7+
lines the maintainer can paste into a merge commit.
8+
9+
This repo exists to **teach visitors to fix bugs by doing**. So the default is to
10+
merge adequate existing contributor work, not to open a fresh PR that races them.
11+
Only open your own PR when no attached PR adequately solves the issue.
12+
13+
## How to run this skill
14+
15+
### 1. Reproduce before you trust the report
16+
17+
- Check out current `master` and actually **run the failing case** from the issue.
18+
- If it reproduces, say so and paste the minimal reproducer (inputs → observed
19+
output, e.g. `nan` + a `RuntimeWarning`).
20+
- If you **cannot** confirm it locally — an optional dependency isn't installed,
21+
the failure needs an external service, the report is too vague — **say that
22+
explicitly rather than guessing.** "Not reproducible in a vanilla checkout"
23+
is a real, useful verdict.
24+
25+
### 2. Classify the issue
26+
27+
Sort each issue into one bucket and act accordingly:
28+
29+
- **Confirmed bug with an adequate open PR** → recommend the specific PR to merge.
30+
- **Confirmed bug, no adequate PR** → open a new PR yourself (see step 5).
31+
- **Not a bug / working-as-intended** → recommend closing, and explain why (e.g.
32+
binary search returning *an* index of a duplicate is correct, not a defect).
33+
- **Feature request mislabeled as a bug** → recommend dropping the `bug` label; do
34+
**not** close it as a bug.
35+
- **Too vague / needs reporter info** → comment **on the issue itself** asking for
36+
the one concrete thing missing (a file path, a traceback, a reproducer), and note
37+
it should be closed if no answer arrives.
38+
- **Environment / optional-dependency, not an algorithm defect** → note it needs
39+
someone with that environment; it is not fixable in a vanilla checkout.
40+
41+
### 3. Examine every attached PR — pick one, name the duplicates
42+
43+
For a bug with several open PRs:
44+
45+
- **Verify each fix's doctest values numerically** against a trusted reference
46+
(`scipy`, `numpy.linalg`, `geopy`, or a brute-force check over random inputs).
47+
Don't take a doctest's word for it — confirm the number.
48+
- Prefer the **first-in PR with the smallest correct diff** that follows repo
49+
convention (doctests over new test files, `raise` over `assert`, no unrelated
50+
reindentation or churn of clean doctests into floating-point noise).
51+
- **Reject out-of-scope "fixes"** — e.g. swapping a real divide-by-zero for a
52+
`1e-15` magic constant makes results implementation-defined. Fix the issue, not
53+
more.
54+
- Identify the byte-for-byte **duplicates** so the maintainer can close them with
55+
thanks in the same action.
56+
57+
### 4. Emit the verdict — fixed output shape
58+
59+
Post one comment that a maintainer can act on directly. For each issue give a
60+
one-line rationale and the exact autoclose line. Two formatting rules matter a lot
61+
to human maintainers scanning the thread:
62+
63+
- **Start every line that references an issue or PR with a Markdown list marker
64+
(`-` or `* `).** GitHub-flavored Markdown only autolinks `#NNNNN` inside a list,
65+
and those autolinks are colored — **purple = merged, red = closed, green = open**
66+
so the maintainer can see merge/close progress at a glance. A bare `#14813` at the
67+
start of a line does not autolink.
68+
- **Merging a PR that closes an issue also closes the issue's other open PRs**, so
69+
fold the duplicates into one autoclose statement rather than listing the winner
70+
alone:
71+
72+
```text
73+
* #14813 — 3x3 inverse returns the transpose → merge #14821
74+
(Closes #14813, Closes #14840, Closes #15045)
75+
```
76+
77+
Recommended shape:
78+
79+
```text
80+
## Confirmed bugs with an adequate open PR — merge
81+
* #<issue> — <one-line what/why> → merge #<pr> (Closes #<issue>, Closes #<dupe>, …)
82+
83+
## Not a bug / not merge-ready
84+
* #<issue> — <feature-request → relabel | needs cleanup | needs a human call>
85+
86+
## Summary — lines to add
87+
* Closes #<issue> → #<pr>
88+
```
89+
90+
### 5. When you must open your own PR
91+
92+
If no attached PR is adequate, open one — but let the contributors keep the credit
93+
where their work was close. Use autoclose keywords in the **commit message body**
94+
so the merge closes the issue *and* the superseded PRs:
95+
96+
```text
97+
Fixes #12233
98+
Fixes #12262
99+
Fixes #13635
100+
```
101+
102+
Follow the [`new-pull-request`](../new-pull-request/SKILL.md) skill for the
103+
mechanics (synced `master`, named branch, checked description box, untouched
104+
`uv.lock`).
105+
106+
## Tone
107+
108+
Be specific and kind. Name the exact PR and the exact reason, credit the
109+
contributor by handle, and offer runners-up detailed feedback so they learn — the
110+
point of the repo is that people come back and fix the next one.

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v7
13+
with:
14+
persist-credentials: false
1315
- uses: astral-sh/setup-uv@v7
1416
with:
1517
enable-cache: true

.github/workflows/devcontainer_ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v7
18+
with:
19+
persist-credentials: false
1820
- uses: devcontainers/ci@v0.3
1921
with:
2022
push: never

.github/workflows/directory_writer.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ jobs:
99
- uses: actions/checkout@v7
1010
with:
1111
fetch-depth: 0
12+
persist-credentials: false
1213
- uses: actions/setup-python@v7
1314
with:
1415
python-version-file: .python-version

0 commit comments

Comments
 (0)