Skip to content

ruff v0.11.2 and rules C4,PERF,UP032,UP034 #163

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def print_benchmarks(times):
"""
print("\nmazelib benchmarking")
print(datetime.now().strftime("%Y-%m-%d %H:%M"))
print("Python version: {0}".format(get_python_version()))
print("mazelib version: {0}".format(version))
print(f"Python version: {get_python_version()}")
print(f"mazelib version: {version}")
print(
"\nTotal Time (seconds): %.5f\n" % sum([sum(times_row) for times_row in times])
)
Expand Down
16 changes: 9 additions & 7 deletions mazelib/generate/Kruskal.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ def generate(self):
forest.append([(row, col)])
grid[row][col] = 0

edges = []
for row in range(2, self.H - 1, 2):
for col in range(1, self.W - 1, 2):
edges.append((row, col))
for row in range(1, self.H - 1, 2):
for col in range(2, self.W - 1, 2):
edges.append((row, col))
edges = [
(row, col)
for row in range(2, self.H - 1, 2)
for col in range(1, self.W - 1, 2)
] + [
(row, col)
for row in range(1, self.H - 1, 2)
for col in range(2, self.W - 1, 2)
]

shuffle(edges)

Expand Down
4 changes: 1 addition & 3 deletions mazelib/mazelib.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ def tostring(self, entrances=False, solutions=False):
return ""

# build the walls of the grid
txt = []
for row in self.grid:
txt.append("".join(["#" if cell else " " for cell in row]))
txt = ["".join("#" if cell else " " for cell in row) for row in self.grid]

# insert the start and end points
if entrances and self.start and self.end:
Expand Down
4 changes: 1 addition & 3 deletions mazelib/solve/ShortestPath.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ def _solve(self):
solutions[s].append(ns[0])

# 3) a solution reaches the end or a dead end when we mark it by appending a None.
num_unfinished = sum(
map(lambda sol: 0 if sol[-1] is None else 1, solutions)
)
num_unfinished = sum(0 if sol[-1] is None else 1 for sol in solutions)

# 4) clean-up solutions
return self._clean_up(solutions)
Expand Down
4 changes: 1 addition & 3 deletions mazelib/solve/ShortestPaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ def _solve(self):
solutions[s].append(ns[0])

# 3) a solution reaches the end or a dead end when we mark it by appending a None.
num_unfinished = sum(
map(lambda sol: 0 if sol[-1] is None else 1, solutions)
)
num_unfinished = sum(0 if sol[-1] is None else 1 for sol in solutions)

# 4) clean-up solutions
solutions = self._clean_up(solutions)
Expand Down
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ classifiers = [
[project.optional-dependencies]
dev = [
"black == 24.10.0",
"ruff == 0.7.4",
"ruff == 0.11.2",
"toml == 0.10.2",
"twine == 4.0.2",
]
Expand All @@ -62,7 +62,7 @@ readme = {file = ["README.md"]}
#######################################################################
[tool.ruff]
# This is the exact version of Ruff we use.
required-version = "0.7.4"
required-version = "0.11.2"

# Assume Python 3.13
target-version = "py313"
Expand Down Expand Up @@ -98,11 +98,13 @@ exclude = [

[tool.ruff.lint]
# Enable pycodestyle (E) and Pyflakes (F) codes by default.
# C4 - flake8-comprehensions
# D - NumPy docstring rules
# N801 - Class name should use CapWords convention
# PERF - Perflint
# SIM - code simplification rules
# TID - tidy imports
select = ["E", "F", "D", "N801", "SIM", "TID"]
select = ["E", "F", "C4", "D", "N801", "PERF", "SIM", "TID"]

# Ruff rules we ignore (for now) because they are not 100% automatable
#
Expand Down Expand Up @@ -142,4 +144,3 @@ ban-relative-imports = "all"

[tool.ruff.lint.pydocstyle]
convention = "numpy"

Loading