From 8501b0c5d94890474fa50d2707b1526d3a1a577b Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Thu, 19 Dec 2024 07:57:39 +0000 Subject: [PATCH] refactor duplicate code in gen_exports --- src/trio/_tools/gen_exports.py | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/trio/_tools/gen_exports.py b/src/trio/_tools/gen_exports.py index b4db597b6..d5d25a32a 100755 --- a/src/trio/_tools/gen_exports.py +++ b/src/trio/_tools/gen_exports.py @@ -180,22 +180,13 @@ def run_linters(file: File, source: str) -> str: SystemExit: If either failed. """ - success, response = run_black(file, source) - if not success: - print(response) - sys.exit(1) - - success, response = run_ruff(file, response) - if not success: # pragma: no cover # Test for run_ruff should catch - print(response) - sys.exit(1) - - success, response = run_black(file, response) - if not success: - print(response) - sys.exit(1) - - return response + for fn in (run_black, run_ruff, run_black): + success, source = fn(file, source) + if not success: + print(source) + sys.exit(1) + + return source def gen_public_wrappers_source(file: File) -> str: