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

* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.9.10 → v0.11.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.9.10...v0.11.0)
- [github.com/abravalheri/validate-pyproject: v0.23 → v0.24](https://github.com/abravalheri/validate-pyproject/compare/v0.23...v0.24)

* Fix ruff issues

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
pre-commit-ci[bot]
2025-03-18 09:53:49 +01:00
committed by GitHub
parent 7ce998b91c
commit edf7c372a9
15 changed files with 26 additions and 28 deletions

View File

@ -16,7 +16,7 @@ repos:
- id: auto-walrus - id: auto-walrus
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.10 rev: v0.11.0
hooks: hooks:
- id: ruff - id: ruff
- id: ruff-format - id: ruff-format
@ -42,7 +42,7 @@ repos:
pass_filenames: false pass_filenames: false
- repo: https://github.com/abravalheri/validate-pyproject - repo: https://github.com/abravalheri/validate-pyproject
rev: v0.23 rev: v0.24
hooks: hooks:
- id: validate-pyproject - id: validate-pyproject

View File

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

View File

@ -54,7 +54,7 @@ def parse_grid(grid):
return False if a contradiction is detected. return False if a contradiction is detected.
""" """
## To start, every square can be any digit; then assign values from the grid. ## 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(): for s, d in grid_values(grid).items():
if d in digits and not assign(values, s, d): if d in digits and not assign(values, s, d):
return False ## (Fail if we can't assign d to square s.) return False ## (Fail if we can't assign d to square s.)
@ -203,7 +203,7 @@ def random_puzzle(assignments=17):
Note the resulting puzzle is not guaranteed to be solvable, but empirically Note the resulting puzzle is not guaranteed to be solvable, but empirically
about 99.8% of them are solvable. Some have multiple solutions. 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): for s in shuffled(squares):
if not assign(values, s, random.choice(values[s])): if not assign(values, s, random.choice(values[s])):
break break

View File

@ -29,7 +29,7 @@ def digital_differential_analyzer_line(
for _ in range(steps): for _ in range(steps):
x += x_increment x += x_increment
y += y_increment y += y_increment
coordinates.append((int(round(x)), int(round(y)))) coordinates.append((round(x), round(y)))
return coordinates return coordinates

View File

@ -239,8 +239,8 @@ def prims_algo(
13 13
""" """
# prim's algorithm for minimum spanning tree # prim's algorithm for minimum spanning tree
dist: dict[T, int] = {node: maxsize for node in graph.connections} dist: dict[T, int] = dict.fromkeys(graph.connections, maxsize)
parent: dict[T, T | None] = {node: None for node in graph.connections} parent: dict[T, T | None] = dict.fromkeys(graph.connections)
priority_queue: MinPriorityQueue[T] = MinPriorityQueue() priority_queue: MinPriorityQueue[T] = MinPriorityQueue()
for node, weight in dist.items(): for node, weight in dist.items():

View File

@ -15,12 +15,12 @@ def rotator():
gear_one.append(i) gear_one.append(i)
del gear_one[0] del gear_one[0]
gear_one_pos += 1 gear_one_pos += 1
if gear_one_pos % int(len(alphabets)) == 0: if gear_one_pos % len(alphabets) == 0:
i = gear_two[0] i = gear_two[0]
gear_two.append(i) gear_two.append(i)
del gear_two[0] del gear_two[0]
gear_two_pos += 1 gear_two_pos += 1
if gear_two_pos % int(len(alphabets)) == 0: if gear_two_pos % len(alphabets) == 0:
i = gear_three[0] i = gear_three[0]
gear_three.append(i) gear_three.append(i)
del gear_three[0] del gear_three[0]

View File

@ -181,7 +181,7 @@ class Test(unittest.TestCase):
test for Matrix method component() test for Matrix method component()
""" """
a = Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]], 3, 3) 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: def test__add__matrix(self) -> None:
""" """

View File

@ -76,7 +76,7 @@ def is_prime(number: int) -> bool:
if number <= 1: if number <= 1:
status = False 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' # if 'number' divisible by 'divisor' then sets 'status'
# of false and break up the loop. # of false and break up the loop.
if number % divisor == 0: if number % divisor == 0:

View File

@ -36,7 +36,7 @@ class Clause:
Represent the literals and an assignment in a clause." Represent the literals and an assignment in a clause."
""" """
# Assign all literals to None initially # 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: def __str__(self) -> str:
""" """

View File

@ -1,5 +1,5 @@
#!/bin/python3 #!/bin/python3
# ruff: noqa # ruff: noqa: PLC3002
""" """
Quine: Quine:

View File

@ -37,7 +37,7 @@ def solution(n: int = 1001) -> int:
""" """
total = 1 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 odd = 2 * i + 1
even = 2 * i even = 2 * i
total = total + 4 * odd**2 - 6 * even total = total + 4 * odd**2 - 6 * even

View File

@ -119,6 +119,7 @@ lint.ignore = [
"PT018", # Assertion should be broken down into multiple parts "PT018", # Assertion should be broken down into multiple parts
"S101", # Use of `assert` detected -- DO NOT FIX "S101", # Use of `assert` detected -- DO NOT FIX
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes -- FIX ME "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 "SLF001", # Private member accessed: `_Iterator` -- FIX ME
"UP038", # Use `X | Y` in `{}` call instead of `(X, Y)` -- DO NOT FIX "UP038", # Use `X | Y` in `{}` call instead of `(X, Y)` -- DO NOT FIX
] ]

View File

@ -9,28 +9,25 @@ except ImportError:
filepaths = list(good_file_paths()) filepaths = list(good_file_paths())
assert filepaths, "good_file_paths() failed!" assert filepaths, "good_file_paths() failed!"
upper_files = [file for file in filepaths if file != file.lower()] if upper_files := [file for file in filepaths if file != file.lower()]:
if upper_files:
print(f"{len(upper_files)} files contain uppercase characters:") print(f"{len(upper_files)} files contain uppercase characters:")
print("\n".join(upper_files) + "\n") print("\n".join(upper_files) + "\n")
space_files = [file for file in filepaths if " " in file] if space_files := [file for file in filepaths if " " in file]:
if space_files:
print(f"{len(space_files)} files contain space characters:") print(f"{len(space_files)} files contain space characters:")
print("\n".join(space_files) + "\n") 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(f"{len(hyphen_files)} files contain hyphen characters:")
print("\n".join(hyphen_files) + "\n") print("\n".join(hyphen_files) + "\n")
nodir_files = [file for file in filepaths if os.sep not in file] if nodir_files := [file for file in filepaths if os.sep not in file]:
if nodir_files:
print(f"{len(nodir_files)} files are not in a directory:") print(f"{len(nodir_files)} files are not in a directory:")
print("\n".join(nodir_files) + "\n") print("\n".join(nodir_files) + "\n")
bad_files = len(upper_files + space_files + hyphen_files + nodir_files) if bad_files := len(upper_files + space_files + hyphen_files + nodir_files):
if bad_files:
import sys import sys
sys.exit(bad_files) sys.exit(bad_files)

View File

@ -61,7 +61,7 @@ class FilesArray:
self.files = files self.files = files
self.empty = set() self.empty = set()
self.num_buffers = len(files) 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): def get_dict(self):
return { return {

View File

@ -36,7 +36,7 @@ LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def get_letter_count(message: str) -> dict[str, int]: 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(): for letter in message.upper():
if letter in LETTERS: if letter in LETTERS:
letter_count[letter] += 1 letter_count[letter] += 1