[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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 26 additions and 28 deletions

View File

@ -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
@ -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

View File

@ -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
@ -68,7 +68,7 @@ class SIUnit(Enum):
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

View File

@ -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.)
@ -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

View File

@ -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

View File

@ -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():

View File

@ -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]

View File

@ -181,7 +181,7 @@ class Test(unittest.TestCase):
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:
"""

View File

@ -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:

View File

@ -36,7 +36,7 @@ class Clause:
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:
"""

View File

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

View File

@ -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

View File

@ -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
]

View File

@ -9,28 +9,25 @@ except ImportError:
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)

View File

@ -61,7 +61,7 @@ class FilesArray:
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 {

View File

@ -36,7 +36,7 @@ LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
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