Skip to content

Commit f442022

Browse files
authored
Merge branch 'master' into fix-ty-invalid-assignment
2 parents 7a8a49a + 2067ce6 commit f442022

12 files changed

Lines changed: 109 additions & 200 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ 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+
#### When a PR fails `ruff check`
37+
38+
Don't just report the failure — try the mechanical fixes and recommend the one
39+
that works, in this order:
40+
41+
1. Run `ruff check --fix file_path.py`. If that makes the file pass, recommend
42+
that solution — these are the fixes `ruff` considers **safe**.
43+
2. If it still fails, run `ruff check --fix --unsafe-fixes file_path.py`. If that
44+
makes the file pass **and** the resulting diff is genuinely safe (it preserves
45+
behavior — review it, don't trust it blindly), recommend that solution and note
46+
that it required `--unsafe-fixes`.
47+
3. If neither passes, or the unsafe fix would change behavior, describe the
48+
remaining rule violations and the manual change the author needs to make.
49+
50+
Always quote the exact rule code(s) `ruff` reports (e.g., `ruff rule UP047`,
51+
`ruff rule RUF100`) so the author can run those commands to read the rules being
52+
flagged. Also, paste the concrete command you ran.
53+
3654
### 3. Other Requirements for Submissions
3755

3856
- [ ] At least one **Wikipedia (or equivalent) URL** documenting the algorithm.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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. Any repo maintainer can undo this if you @mention them on the closed pull request.
23+
24+
### 1. Before contributing / Is this an algorithm?
25+
26+
- [ ] The change adds, fixes, or documents **one algorithm** — not multiple, and
27+
not both code and doctest changes in the same PR.
28+
- [ ] It is a genuine algorithm or data structure (see the *What is an Algorithm?*
29+
section), not a script, snippet, how-to-use for an existing API, or exercise
30+
dump.
31+
- [ ] It is **not already in the repository** (search the existing directories).
32+
- [ ] **No earlier open PR** already does the same thing — link it if one exists.
33+
- [ ] Properly attributed — no plagiarism; prior sources credited.
34+
35+
### 2. Coding Style
36+
37+
- [ ] `from __future__ import annotations` is not needed because this repo only uses
38+
the latest version of CPython.
39+
- [ ] File and directory names are lowercase, use underscores, and land inside an
40+
existing directory.
41+
- [ ] Public functions/classes have **type hints**.
42+
- [ ] Public functions have **doctests that actually pass**.
43+
- [ ] Descriptive variable and function names (no single letters where a word helps).
44+
- [ ] Code is formatted and lint-clean (`ruff`, `pre-commit`).
45+
- [ ] `DIRECTORY.md` and `README.md` are **not hand-edited** — the
46+
`algorithms-keeper` bot regenerates them automatically after merge.
47+
48+
### 3. Other Requirements for Submissions
49+
50+
- [ ] At least one **Wikipedia (or equivalent) URL** documenting the algorithm.
51+
- [ ] Docstring explains what the function does and its parameters/returns.
52+
- [ ] No unnecessary third-party dependencies.

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ repos:
2929
- tomli
3030

3131
- repo: https://github.com/astral-sh/ruff-pre-commit
32-
rev: v0.16.5
32+
rev: v0.16.6
3333
hooks:
3434
- id: ruff-check
3535
- id: ruff-format
3636

3737
- repo: https://github.com/tox-dev/pyproject-fmt
38-
rev: v2.28.1
38+
rev: v2.29.3
3939
hooks:
4040
- id: pyproject-fmt
4141

@@ -48,7 +48,7 @@ repos:
4848
pass_filenames: false
4949

5050
- repo: https://github.com/astral-sh/uv-pre-commit
51-
rev: 0.12.7
51+
rev: 0.12.10
5252
hooks:
5353
- id: uv-lock
5454

DIRECTORY.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,8 +696,6 @@
696696
* [Support Vector Machines](machine_learning/support_vector_machines.py)
697697
* [T Stochastic Neighbour Embedding](machine_learning/t_stochastic_neighbour_embedding.py)
698698
* [Word Frequency Functions](machine_learning/word_frequency_functions.py)
699-
* [Xgboost Classifier](machine_learning/xgboost_classifier.py)
700-
* [Xgboost Regressor](machine_learning/xgboost_regressor.py)
701699

702700
## [Maths](maths)
703701
* [Abs](maths/abs.py)

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
<a href="https://the-algorithms.com/discord">
1818
<img src="https://img.shields.io/discord/808045925556682782.svg?logo=discord&colorB=7289DA&style=flat-square" height="20" alt="Discord chat">
1919
</a>
20-
<a href="https://gitter.im/TheAlgorithms/community">
21-
<img src="https://img.shields.io/badge/Chat-Gitter-ff69b4.svg?label=Chat&logo=gitter&style=flat-square" height="20" alt="Gitter chat">
22-
</a>
2320

2421
<!-- Second row: -->
2522
<br>
@@ -45,7 +42,7 @@ Implementations are for learning purposes only. They may be less efficient than
4542

4643
## 🌐 Community Channels
4744

48-
We are on [Discord](https://the-algorithms.com/discord) and [Gitter](https://gitter.im/TheAlgorithms/community)! Community channels are a great way for you to ask questions and get help. Please join us!
45+
We are on [Discord](https://the-algorithms.com/discord)! Community channels are a great way for you to ask questions and get help. Please join us!
4946

5047
## 📜 List of Algorithms
5148

graphs/kahns_algorithm_topo.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from collections import deque
2+
3+
14
def topological_sort(graph: dict[int, list[int]]) -> list[int] | None:
25
"""
36
Perform topological sorting of a Directed Acyclic Graph (DAG)
@@ -21,10 +24,17 @@ def topological_sort(graph: dict[int, list[int]]) -> list[int] | None:
2124
2225
>>> graph_with_cycle = {0: [1], 1: [2], 2: [0]}
2326
>>> topological_sort(graph_with_cycle)
27+
28+
>>> sparse_graph = {10: [20], 20: []}
29+
>>> topological_sort(sparse_graph)
30+
[10, 20]
31+
32+
>>> sparse_cycle = {10: [20], 20: [10]}
33+
>>> topological_sort(sparse_cycle)
2434
"""
2535

26-
indegree = [0] * len(graph)
27-
queue = []
36+
indegree = dict.fromkeys(graph, 0)
37+
queue: deque[int] = deque()
2838
topo_order = []
2939
processed_vertices_count = 0
3040

@@ -34,13 +44,13 @@ def topological_sort(graph: dict[int, list[int]]) -> list[int] | None:
3444
indegree[i] += 1
3545

3646
# Add all vertices with 0 indegree to the queue
37-
for i in range(len(indegree)):
38-
if indegree[i] == 0:
39-
queue.append(i)
47+
for vertex, count in indegree.items():
48+
if count == 0:
49+
queue.append(vertex)
4050

4151
# Perform BFS
4252
while queue:
43-
vertex = queue.pop(0)
53+
vertex = queue.popleft()
4454
processed_vertices_count += 1
4555
topo_order.append(vertex)
4656

machine_learning/xgboost_classifier.py

Lines changed: 0 additions & 79 deletions
This file was deleted.

machine_learning/xgboost_regressor.py

Lines changed: 0 additions & 66 deletions
This file was deleted.

maths/matrix_exponentiation.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
"""Matrix Exponentiation"""
2-
3-
import timeit
4-
51
"""
62
Matrix Exponentiation is a technique to solve linear recurrences in logarithmic time.
73
You read more about it here:
84
https://zobayer.blogspot.com/2010/11/matrix-exponentiation.html
95
https://www.hackerearth.com/practice/notes/matrix-exponentiation-1/
106
"""
117

8+
import timeit
9+
1210

1311
class Matrix:
1412
def __init__(self, arg: list[list] | int) -> None:

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ dependencies = [
2727
"statsmodels>=0.14.4",
2828
"sympy>=1.13.3",
2929
"typing-extensions>=4.12.2",
30-
"xgboost>=2.1.3",
3130
]
3231

3332
[dependency-groups]
@@ -174,7 +173,9 @@ lint.pylint.max-returns = 8 # default: 6
174173
lint.pylint.max-statements = 88 # default: 50
175174

176175
[tool.codespell]
177-
ignore-words-list = "3rt,abd,aer,ans,bitap,crate,damon,fo,followings,hist,iff,kwanza,manuel,mater,secant,som,sur,tim,toi,zar"
176+
ignore-words-list = """\
177+
3rt,abd,aer,ans,bitap,crate,damon,fo,followings,hist,iff,kwanza,manuel,mater,secant,som,sur,tim,toi,zar\
178+
"""
178179
skip = """\
179180
./.*,*.json,*.lock,ciphers/prehistoric_men.txt,project_euler/problem_022/p022_names.txt,pyproject.toml,strings/dictio\
180181
nary.txt,strings/words.txt\

0 commit comments

Comments
 (0)