From 9c21af627c52a3ae06e746fa4506168ca42eef53 Mon Sep 17 00:00:00 2001 From: David Zwicker Date: Wed, 3 Jan 2024 19:34:59 +0100 Subject: [PATCH] Improved pyupgrade script --- docs/source/conf.py | 2 +- docs/source/run_autodoc.py | 2 +- docs/sphinx_ext/simplify_typehints.py | 4 ++-- docs/sphinx_ext/toctree_filter.py | 2 +- scripts/format_code.sh | 2 +- tests/tools/test_numba.py | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 0892ad0d..bb576097 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -154,7 +154,7 @@ # Latex figure (float) alignment # # 'figure_align': 'htbp', - "preamble": "\setcounter{tocdepth}{4}" + "preamble": r"\setcounter{tocdepth}{4}" } # Grouping the document tree into LaTeX files. List of tuples diff --git a/docs/source/run_autodoc.py b/docs/source/run_autodoc.py index 1ecaef43..26b3157e 100755 --- a/docs/source/run_autodoc.py +++ b/docs/source/run_autodoc.py @@ -32,7 +32,7 @@ def replace_in_file(infile, replacements, outfile=None): if outfile is None: outfile = infile - with open(infile, "r") as fp: + with open(infile) as fp: content = fp.read() for key, value in replacements.items(): diff --git a/docs/sphinx_ext/simplify_typehints.py b/docs/sphinx_ext/simplify_typehints.py index 93368806..ef853cc1 100644 --- a/docs/sphinx_ext/simplify_typehints.py +++ b/docs/sphinx_ext/simplify_typehints.py @@ -48,8 +48,8 @@ # replacement rules based on regular expressions REPLACEMENTS_REGEX = { # remove full package path and only leave the module/class identifier - "pde\.(\w+\.)*": "", - "typing\.": "", + r"pde\.(\w+\.)*": "", + r"typing\.": "", } diff --git a/docs/sphinx_ext/toctree_filter.py b/docs/sphinx_ext/toctree_filter.py index 0deb2721..964aaed5 100644 --- a/docs/sphinx_ext/toctree_filter.py +++ b/docs/sphinx_ext/toctree_filter.py @@ -6,7 +6,7 @@ class TocTreeFilter(TocTree): """directive to filter table-of-contents entries""" - hasPat = re.compile("^\s*:(.+):(.+)$") + hasPat = re.compile(r"^\s*:(.+):(.+)$") # Remove any entries in the content that we dont want and strip # out any filter prefixes that we want but obviously don't want the diff --git a/scripts/format_code.sh b/scripts/format_code.sh index a4db979a..2d8651aa 100755 --- a/scripts/format_code.sh +++ b/scripts/format_code.sh @@ -3,7 +3,7 @@ echo "Upgrading python syntax..." pushd .. > /dev/null -pyupgrade --py38-plus **/*.py +find . -name '*.py' -exec pyupgrade --py38-plus {} + popd > /dev/null echo "Formating import statements..." diff --git a/tests/tools/test_numba.py b/tests/tools/test_numba.py index 46bc3a4d..c8bbe1b2 100644 --- a/tests/tools/test_numba.py +++ b/tests/tools/test_numba.py @@ -40,7 +40,7 @@ def test_counter(): assert int(c1) is 1 c1 += 2 - assert int(c1) is 3 + assert int(c1) == 3 c2 = Counter(3) assert c1 is not c2