From d127e13762454749883bbdd424f5e046682c2907 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Mon, 15 Jan 2024 10:29:46 +0100 Subject: [PATCH] enable ruff up rules --- pyproject.toml | 5 ++++- template/utils/_checks.py | 6 +++--- template/utils/_fixes.py | 2 +- template/utils/tests/test_docs.py | 2 +- template/utils/tests/test_logs.py | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5bcc0675..4fd64660 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -148,8 +148,11 @@ extend-exclude = [ 'setup.py', ] line-length = 88 -select = ["E", "F", "W"] +select = ["E", "F", "W", "UP"] target-version = 'py39' +ignore = [ + "UP007", # 'Use `X | Y` for type annotations', requires python 3.10 +] [tool.ruff.format] docstring-code-format = true diff --git a/template/utils/_checks.py b/template/utils/_checks.py index 81279119..99663b01 100644 --- a/template/utils/_checks.py +++ b/template/utils/_checks.py @@ -160,9 +160,9 @@ def check_value( if len(allowed_values) == 1: options = "The only allowed value is %s" % repr(allowed_values[0]) elif len(allowed_values) == 2: - options = "Allowed values are %s and %s" % ( - repr(allowed_values[0]), - repr(allowed_values[1]), + options = ( + f"Allowed values are {repr(allowed_values[0])} " + f"and {repr(allowed_values[1])}" ) else: options = "Allowed values are " diff --git a/template/utils/_fixes.py b/template/utils/_fixes.py index e4a06453..d27efdbd 100644 --- a/template/utils/_fixes.py +++ b/template/utils/_fixes.py @@ -10,7 +10,7 @@ # https://github.com/sphinx-gallery/sphinx-gallery/issues/1112 -class WrapStdOut(object): +class WrapStdOut: """Dynamically wrap to sys.stdout. This makes packages that monkey-patch sys.stdout (e.g.doctest, sphinx-gallery) work diff --git a/template/utils/tests/test_docs.py b/template/utils/tests/test_docs.py index f1256ddf..5696cedd 100644 --- a/template/utils/tests/test_docs.py +++ b/template/utils/tests/test_docs.py @@ -217,7 +217,7 @@ def test_docdict_order(): # read the file as text, and get entries via regex docs_path = Path(__file__).parents[1] / "_docs.py" assert docs_path.is_file() - with open(docs_path, "r", encoding="UTF-8") as fid: + with open(docs_path, encoding="UTF-8") as fid: docs = fid.read() entries = re.findall(r'docdict\[(?:\n )?["\'](.+)["\']\n?\] = ', docs) # test length, uniqueness and order diff --git a/template/utils/tests/test_logs.py b/template/utils/tests/test_logs.py index 95a7cff6..b768adf4 100644 --- a/template/utils/tests/test_logs.py +++ b/template/utils/tests/test_logs.py @@ -133,7 +133,7 @@ def test_file_handler(tmp_path): logger.handlers[-1].close() - with open(fname, mode="r") as file: + with open(fname) as file: lines = file.readlines() assert len(lines) == 2