Skip to content

Commit 9b0dd83

Browse files
committed
Comment on ruff rules
1 parent 030b6be commit 9b0dd83

File tree

4 files changed

+55
-62
lines changed

4 files changed

+55
-62
lines changed

Diff for: data_structures/heap/heap_generic.py

-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ def test_heap() -> None:
166166
>>> h.get_top()
167167
[9, -40]
168168
"""
169-
pass
170169

171170

172171
if __name__ == "__main__":

Diff for: maths/eulers_totient.py

+15-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Eulers Totient function finds the number of relative primes of a number n from 1 to n
22
def totient(n: int) -> list:
3+
"""
4+
>>> n = 10
5+
>>> totient_calculation = totient(n)
6+
>>> for i in range(1, n):
7+
... print(f"{i} has {totient_calculation[i]} relative primes.")
8+
1 has 0 relative primes.
9+
2 has 1 relative primes.
10+
3 has 2 relative primes.
11+
4 has 2 relative primes.
12+
5 has 4 relative primes.
13+
6 has 2 relative primes.
14+
7 has 6 relative primes.
15+
8 has 4 relative primes.
16+
9 has 6 relative primes.
17+
"""
318
is_prime = [True for i in range(n + 1)]
419
totients = [i - 1 for i in range(n + 1)]
520
primes = []
@@ -20,25 +35,6 @@ def totient(n: int) -> list:
2035
return totients
2136

2237

23-
def test_totient() -> None:
24-
"""
25-
>>> n = 10
26-
>>> totient_calculation = totient(n)
27-
>>> for i in range(1, n):
28-
... print(f"{i} has {totient_calculation[i]} relative primes.")
29-
1 has 0 relative primes.
30-
2 has 1 relative primes.
31-
3 has 2 relative primes.
32-
4 has 2 relative primes.
33-
5 has 4 relative primes.
34-
6 has 2 relative primes.
35-
7 has 6 relative primes.
36-
8 has 4 relative primes.
37-
9 has 6 relative primes.
38-
"""
39-
pass
40-
41-
4238
if __name__ == "__main__":
4339
import doctest
4440

Diff for: maths/pythagoras.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,13 @@ def __repr__(self) -> str:
1414

1515

1616
def distance(a: Point, b: Point) -> float:
17-
return math.sqrt(abs((b.x - a.x) ** 2 + (b.y - a.y) ** 2 + (b.z - a.z) ** 2))
18-
19-
20-
def test_distance() -> None:
2117
"""
2218
>>> point1 = Point(2, -1, 7)
2319
>>> point2 = Point(1, -3, 5)
2420
>>> print(f"Distance from {point1} to {point2} is {distance(point1, point2)}")
2521
Distance from Point(2, -1, 7) to Point(1, -3, 5) is 3.0
2622
"""
27-
pass
23+
return math.sqrt(abs((b.x - a.x) ** 2 + (b.y - a.y) ** 2 + (b.z - a.z) ** 2))
2824

2925

3026
if __name__ == "__main__":

Diff for: pyproject.toml

+39-37
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,51 @@ ignore-words-list = "3rt,ans,crate,damon,fo,followings,hist,iff,kwanza,mater,sec
1717
skip = "./.*,*.json,ciphers/prehistoric_men.txt,project_euler/problem_022/p022_names.txt,pyproject.toml,strings/dictionary.txt,strings/words.txt"
1818

1919
[tool.ruff]
20-
ignore = [
21-
"B904",
22-
"B905",
23-
"E741",
24-
"N999",
25-
"PLC1901",
26-
"PLR2004",
27-
"PLR5501",
28-
"PLW0120",
29-
"PLW060",
30-
"PLW2901",
31-
"RUF00",
32-
"RUF100",
33-
"S101",
34-
"S105",
35-
"S113",
36-
"UP038",
20+
ignore = [ # `ruff rule S101` for a description of that rule
21+
"B904", # B904: Within an `except` clause, raise exceptions with `raise ... from err`
22+
"B905", # B905: `zip()` without an explicit `strict=` parameter
23+
"E741", # E741: Ambiguous variable name 'l'
24+
"G004", # G004 Logging statement uses f-string
25+
"N999", # N999: Invalid module name
26+
"PLC1901", # PLC1901: `{}` can be simplified to `{}` as an empty string is falsey
27+
"PLR2004", # PLR2004: Magic value used in comparison
28+
"PLR5501", # PLR5501: Consider using `elif` instead of `else`
29+
"PLW0120", # PLW0120: `else` clause on loop without a `break` statement
30+
"PLW060", # PLW060: Using global for `{name}` but no assignment is done -- DO NOT FIX
31+
"PLW2901", # PLW2901: Redefined loop variable
32+
"RUF00", # RUF00: Ambiguous unicode character -- DO NOT FIX
33+
"RUF100", # RUF100: Unused `noqa` directive
34+
"S101", # S101: Use of `assert` detected -- DO NOT FIX
35+
"S105", # S105: Possible hardcoded password: 'password'
36+
"S113", # S113: Probable use of requests call without timeout
37+
"UP038", # UP038: Use `X | Y` in `{}` call instead of `(X, Y)` -- DO NOT FIX
3738
]
38-
select = [
39-
"A",
40-
"B",
41-
"C40",
42-
"C9",
43-
"E",
44-
"F",
45-
"I",
46-
"N",
47-
"PLC",
48-
"PLE",
49-
"PLR",
50-
"PLW",
51-
"RUF",
52-
"S",
53-
"UP",
54-
"W",
55-
"YTT",
39+
select = [ # https://beta.ruff.rs/docs/rules
40+
"A", # A: builtins
41+
"B", # B: bugbear
42+
"C40", # C40: comprehensions
43+
"C90", # C90: mccabe code complexity
44+
"E", # E: pycodestyle errors
45+
"F", # F: pyflakes
46+
"G", # G: logging format
47+
"I", # I: isort
48+
"N", # N: pep8 naming
49+
"PL", # PL: pylint
50+
"PIE", # PIE: pie
51+
"PYI", # PYI: type hinting stub files
52+
"RUF", # RUF: ruff
53+
"S", # S: bandit
54+
"TID", # TID: tidy imports
55+
"UP", # UP: pyupgrade
56+
"W", # W: pycodestyle warnings
57+
"YTT", # YTT: Year Two Thousand
5658
]
5759
target-version = "py311"
5860

59-
[tool.ruff.mccabe]
61+
[tool.ruff.mccabe] # DO NOT INCREASE THIS VALUE
6062
max-complexity = 20 # default: 10
6163

62-
[tool.ruff.pylint]
64+
[tool.ruff.pylint] # DO NOT INCREASE THESE VALUES
6365
max-args = 10 # default: 5
6466
max-branches = 20 # default: 12
6567
max-returns = 8 # default: 6

0 commit comments

Comments
 (0)