Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #12623

Merged
merged 2 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:
- id: auto-walrus

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.10
rev: v0.11.0
hooks:
- id: ruff
- id: ruff-format
Expand All @@ -42,7 +42,7 @@ repos:
pass_filenames: false

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.23
rev: v0.24
hooks:
- id: validate-pyproject

Expand Down
4 changes: 2 additions & 2 deletions conversions/prefix_conversions_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SIUnit(Enum):
yocto = -24

@classmethod
def get_positive(cls: type[T]) -> dict:
def get_positive(cls) -> dict:
"""
Returns a dictionary with only the elements of this enum
that has a positive value
Expand All @@ -68,7 +68,7 @@ def get_positive(cls: type[T]) -> dict:
return {unit.name: unit.value for unit in cls if unit.value > 0}

@classmethod
def get_negative(cls: type[T]) -> dict:
def get_negative(cls) -> dict:
"""
Returns a dictionary with only the elements of this enum
that has a negative value
Expand Down
4 changes: 2 additions & 2 deletions data_structures/arrays/sudoku_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def parse_grid(grid):
return False if a contradiction is detected.
"""
## To start, every square can be any digit; then assign values from the grid.
values = {s: digits for s in squares}
values = dict.fromkeys(squares, digits)
for s, d in grid_values(grid).items():
if d in digits and not assign(values, s, d):
return False ## (Fail if we can't assign d to square s.)
Expand Down Expand Up @@ -203,7 +203,7 @@ def random_puzzle(assignments=17):
Note the resulting puzzle is not guaranteed to be solvable, but empirically
about 99.8% of them are solvable. Some have multiple solutions.
"""
values = {s: digits for s in squares}
values = dict.fromkeys(squares, digits)
for s in shuffled(squares):
if not assign(values, s, random.choice(values[s])):
break
Expand Down
2 changes: 1 addition & 1 deletion graphics/digital_differential_analyzer_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def digital_differential_analyzer_line(
for _ in range(steps):
x += x_increment
y += y_increment
coordinates.append((int(round(x)), int(round(y))))
coordinates.append((round(x), round(y)))
return coordinates


Expand Down
4 changes: 2 additions & 2 deletions graphs/minimum_spanning_tree_prims2.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ def prims_algo(
13
"""
# prim's algorithm for minimum spanning tree
dist: dict[T, int] = {node: maxsize for node in graph.connections}
parent: dict[T, T | None] = {node: None for node in graph.connections}
dist: dict[T, int] = dict.fromkeys(graph.connections, maxsize)
parent: dict[T, T | None] = dict.fromkeys(graph.connections)

priority_queue: MinPriorityQueue[T] = MinPriorityQueue()
for node, weight in dist.items():
Expand Down
4 changes: 2 additions & 2 deletions hashes/enigma_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ def rotator():
gear_one.append(i)
del gear_one[0]
gear_one_pos += 1
if gear_one_pos % int(len(alphabets)) == 0:
if gear_one_pos % len(alphabets) == 0:
i = gear_two[0]
gear_two.append(i)
del gear_two[0]
gear_two_pos += 1
if gear_two_pos % int(len(alphabets)) == 0:
if gear_two_pos % len(alphabets) == 0:
i = gear_three[0]
gear_three.append(i)
del gear_three[0]
Expand Down
2 changes: 1 addition & 1 deletion linear_algebra/src/test_linear_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def test_component_matrix(self) -> None:
test for Matrix method component()
"""
a = Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]], 3, 3)
assert a.component(2, 1) == 7, 0.01
assert a.component(2, 1) == 7, "0.01"

def test__add__matrix(self) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion maths/primelib.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def is_prime(number: int) -> bool:
if number <= 1:
status = False

for divisor in range(2, int(round(sqrt(number))) + 1):
for divisor in range(2, round(sqrt(number)) + 1):
# if 'number' divisible by 'divisor' then sets 'status'
# of false and break up the loop.
if number % divisor == 0:
Expand Down
2 changes: 1 addition & 1 deletion other/davis_putnam_logemann_loveland.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, literals: list[str]) -> None:
Represent the literals and an assignment in a clause."
"""
# Assign all literals to None initially
self.literals: dict[str, bool | None] = {literal: None for literal in literals}
self.literals: dict[str, bool | None] = dict.fromkeys(literals)

def __str__(self) -> str:
"""
Expand Down
2 changes: 1 addition & 1 deletion other/quine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/python3
# ruff: noqa
# ruff: noqa: PLC3002
"""
Quine:

Expand Down
2 changes: 1 addition & 1 deletion project_euler/problem_028/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def solution(n: int = 1001) -> int:
"""
total = 1

for i in range(1, int(ceil(n / 2.0))):
for i in range(1, ceil(n / 2.0)):
odd = 2 * i + 1
even = 2 * i
total = total + 4 * odd**2 - 6 * even
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ lint.ignore = [
"PT018", # Assertion should be broken down into multiple parts
"S101", # Use of `assert` detected -- DO NOT FIX
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes -- FIX ME
"SIM905", # Consider using a list literal instead of `str.split` -- DO NOT FIX
"SLF001", # Private member accessed: `_Iterator` -- FIX ME
"UP038", # Use `X | Y` in `{}` call instead of `(X, Y)` -- DO NOT FIX
]
Expand Down
17 changes: 7 additions & 10 deletions scripts/validate_filenames.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,25 @@
filepaths = list(good_file_paths())
assert filepaths, "good_file_paths() failed!"

upper_files = [file for file in filepaths if file != file.lower()]
if upper_files:
if upper_files := [file for file in filepaths if file != file.lower()]:
print(f"{len(upper_files)} files contain uppercase characters:")
print("\n".join(upper_files) + "\n")

space_files = [file for file in filepaths if " " in file]
if space_files:
if space_files := [file for file in filepaths if " " in file]:
print(f"{len(space_files)} files contain space characters:")
print("\n".join(space_files) + "\n")

hyphen_files = [file for file in filepaths if "-" in file]
if hyphen_files:
if hyphen_files := [
file for file in filepaths if "-" in file and "/site-packages/" not in file
]:
print(f"{len(hyphen_files)} files contain hyphen characters:")
print("\n".join(hyphen_files) + "\n")

nodir_files = [file for file in filepaths if os.sep not in file]
if nodir_files:
if nodir_files := [file for file in filepaths if os.sep not in file]:
print(f"{len(nodir_files)} files are not in a directory:")
print("\n".join(nodir_files) + "\n")

bad_files = len(upper_files + space_files + hyphen_files + nodir_files)
if bad_files:
if bad_files := len(upper_files + space_files + hyphen_files + nodir_files):
import sys

sys.exit(bad_files)
2 changes: 1 addition & 1 deletion sorts/external_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self, files):
self.files = files
self.empty = set()
self.num_buffers = len(files)
self.buffers = {i: None for i in range(self.num_buffers)}
self.buffers = dict.fromkeys(range(self.num_buffers))

def get_dict(self):
return {
Expand Down
2 changes: 1 addition & 1 deletion strings/frequency_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@


def get_letter_count(message: str) -> dict[str, int]:
letter_count = {letter: 0 for letter in string.ascii_uppercase}
letter_count = dict.fromkeys(string.ascii_uppercase, 0)
for letter in message.upper():
if letter in LETTERS:
letter_count[letter] += 1
Expand Down