Skip to content

Commit 126908c

Browse files
chore: add more ruff with autofixes (#644)
* chore: add more ruff with autofixes Signed-off-by: Henry Schreiner <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Henry Schreiner <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 82c9c4e commit 126908c

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,15 @@ extend-select = [
168168
"PD", # pandas-vet
169169
"FURB", # refurb
170170
"PYI", # flake8-pyi
171+
"BLE", # flake8-blind-except
172+
"FA", # flake8-future-annotations
173+
"FLY", # flynt
174+
"ISC", # flake8-implicit-str-concat
175+
"Q", # flake8-quotes
176+
"RSE", # flake8-raise
177+
"SLOT", # flake8-slots
178+
"T10", # flake8-debugger
179+
"TC", # flake8-type-checking
171180
]
172181
ignore = [
173182
"PLR09", # Too many <...>
@@ -186,3 +195,4 @@ ignore = [
186195
"docs/conf.py" = ["T20"]
187196
"src/mplhep/_dev.py" = ["T20"]
188197
"test_*.py" = ["T20"]
198+
"src/mplhep/styles/*.py" = ["FLY002"]

src/mplhep/_dev.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
Usage: ./dev [command] [options] or ./dev for interactive mode
55
"""
66

7+
from __future__ import annotations
8+
79
import argparse
810
import datetime
911
import importlib.util
@@ -14,7 +16,6 @@
1416
import subprocess
1517
import sys
1618
from pathlib import Path
17-
from typing import Optional
1819

1920
try:
2021
import questionary
@@ -99,7 +100,7 @@ def _run_command_with_confirmation(
99100

100101
return self._run_command(cmd)
101102

102-
def _run_command(self, cmd: list[str], cwd: Optional[Path] = None) -> bool:
103+
def _run_command(self, cmd: list[str], cwd: Path | None = None) -> bool:
103104
"""Run a command and return True if successful."""
104105
try:
105106
self._print_header(f"Running: {' '.join(cmd)}")
@@ -178,10 +179,10 @@ def _find_files_to_clean(self) -> list[Path]:
178179

179180
def cmd_test(
180181
self,
181-
jobs: Optional[int] = None,
182-
filter_pattern: Optional[str] = None,
182+
jobs: int | None = None,
183+
filter_pattern: str | None = None,
183184
skip_cleanup: bool = False,
184-
extra_args: Optional[list[str]] = None,
185+
extra_args: list[str] | None = None,
185186
) -> bool:
186187
"""Run pytest with matplotlib comparison."""
187188
if jobs is None:
@@ -282,7 +283,7 @@ def cmd_baseline(self) -> bool:
282283

283284
return success
284285

285-
def cmd_precommit(self, extra_args: Optional[list[str]] = None) -> bool:
286+
def cmd_precommit(self, extra_args: list[str] | None = None) -> bool:
286287
"""Run pre-commit hooks on all files."""
287288
self._print_header("Running Pre-commit Hooks")
288289

@@ -351,7 +352,7 @@ def cmd_docs(
351352
port: int = 8000,
352353
clean: bool = True,
353354
fast: bool = False,
354-
extra_args: Optional[list[str]] = None,
355+
extra_args: list[str] | None = None,
355356
) -> bool:
356357
"""Build or serve documentation."""
357358
# Check if mkdocs is available
@@ -372,7 +373,7 @@ def cmd_docs(
372373
return False
373374

374375
def _build_docs(
375-
self, clean: bool, fast: bool, extra_args: Optional[list[str]] = None
376+
self, clean: bool, fast: bool, extra_args: list[str] | None = None
376377
) -> bool:
377378
"""Build documentation."""
378379
if fast:
@@ -411,7 +412,7 @@ def _build_docs(
411412
return success
412413

413414
def _serve_docs(
414-
self, port: int, fast: bool, extra_args: Optional[list[str]] = None
415+
self, port: int, fast: bool, extra_args: list[str] | None = None
415416
) -> bool:
416417
"""Serve documentation locally."""
417418
if fast:
@@ -489,8 +490,8 @@ def cmd_clean(self) -> bool:
489490
def cmd_benchmark(
490491
self,
491492
action: str = "run",
492-
baseline_name: Optional[str] = None,
493-
compare_with: Optional[str] = None,
493+
baseline_name: str | None = None,
494+
compare_with: str | None = None,
494495
) -> bool:
495496
"""Run performance benchmarks."""
496497
# Check if pytest-benchmark is available
@@ -523,7 +524,7 @@ def _check_benchmark_available(self) -> bool:
523524
self._print_warning("Install with: pip install pytest-benchmark")
524525
return False
525526

526-
def _run_benchmarks(self, baseline_name: Optional[str] = None) -> bool:
527+
def _run_benchmarks(self, baseline_name: str | None = None) -> bool:
527528
"""Run benchmark tests."""
528529
# Build benchmark command
529530
cmd = [
@@ -562,7 +563,7 @@ def _run_benchmarks(self, baseline_name: Optional[str] = None) -> bool:
562563

563564
return success
564565

565-
def _compare_benchmarks(self, compare_with: Optional[str] = None) -> bool:
566+
def _compare_benchmarks(self, compare_with: str | None = None) -> bool:
566567
"""Compare current benchmarks with a baseline."""
567568
benchmark_dir = self.project_root / "tests" / "baseline" / "benchmark"
568569

@@ -808,7 +809,7 @@ def _get_style(self):
808809

809810
def _get_text_input(
810811
self, prompt: str, default: str = "", fallback_prompt: str = ""
811-
) -> Optional[str]:
812+
) -> str | None:
812813
"""Get text input with questionary or basic fallback."""
813814
if HAS_QUESTIONARY and questionary is not None:
814815
return questionary.text(prompt, default=default, style=self.style).ask()
@@ -823,7 +824,7 @@ def _get_text_input(
823824

824825
def _get_choice(
825826
self, prompt: str, choices: list[tuple], fallback_prompt: str = ""
826-
) -> Optional[str]:
827+
) -> str | None:
827828
"""Get choice selection with questionary or basic fallback."""
828829
if HAS_QUESTIONARY and questionary is not None:
829830
choice_objects = [

src/mplhep/_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from collections.abc import Iterable, Sequence
43
from numbers import Real
54
from typing import TYPE_CHECKING, Any
65

@@ -13,7 +12,7 @@
1312
from uhi.typing.plottable import PlottableAxis, PlottableHistogram
1413

1514
if TYPE_CHECKING:
16-
pass
15+
from collections.abc import Iterable, Sequence
1716

1817
ArrayLike = Any
1918

src/mplhep/label.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -913,9 +913,9 @@ def exp_label(
913913
# Build label following main branch logic
914914
_label = text
915915
if supp: # If supp is truthy, prepend "Supplementary"
916-
_label = " ".join(["Supplementary", _label])
916+
_label = f"Supplementary {_label}"
917917
if not data:
918-
_label = " ".join(["Simulation", _label])
918+
_label = f"Simulation {_label}"
919919
# Clean up extra whitespace
920920
llabel = " ".join(_label.split())
921921

@@ -1013,7 +1013,7 @@ def _normalize_labels(labels_input):
10131013
# At this point, labels is guaranteed to be list[tuple[str, str]]
10141014
tuple_labels: list[tuple[str, str]] = labels # type: ignore[assignment]
10151015
for label_text, suffix in tuple_labels:
1016-
label_base.set_text(" ".join([_sim, label_text]).lstrip())
1016+
label_base.set_text(f"{_sim} {label_text}".lstrip())
10171017

10181018
def _construct_filename(base_fname: str, suffix: str) -> str:
10191019
"""Construct output filename from base name and suffix."""

0 commit comments

Comments
 (0)