From 9afc249af0646359ae2d28f6412d8ac4c23635c3 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 24 Mar 2024 09:26:06 -0500 Subject: [PATCH] refactor!(ruff): Run all automated fixes as of ruff 0.3.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ruff check --select ALL . --fix --unsafe-fixes --preview --show-fixes; ruff format . Fixed 14 errors: - docs/conf.py: 1 × RET505 (superfluous-else-return) - src/doctest_docutils.py: 2 × ANN204 (missing-return-type-special-method) 1 × T201 (print) 1 × RUF100 (unused-noqa) 1 × RSE102 (unnecessary-paren-on-raise-exception) 1 × PIE810 (multiple-starts-ends-with) 1 × PLR6201 (literal-membership) - src/linkify_issues.py: 1 × RET504 (unnecessary-assign) - src/pytest_doctest_docutils.py: 1 × PLR6201 (literal-membership) - tests/conftest.py: 1 × PT003 (pytest-extraneous-scope-function) 1 × PT022 (pytest-useless-yield-fixture) --- docs/conf.py | 15 +++++++-------- src/doctest_docutils.py | 14 +++++++------- src/linkify_issues.py | 3 +-- src/pytest_doctest_docutils.py | 2 +- tests/conftest.py | 6 +++--- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 5b7241c..4893e1f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -196,14 +196,13 @@ def linkcode_resolve(domain: str, info: t.Dict[str, str]) -> t.Union[None, str]: fn, linespec, ) - else: - return "{}/blob/v{}/{}/{}{}".format( - about["__github__"], - about["__version__"], - "src", - fn, - linespec, - ) + return "{}/blob/v{}/{}/{}{}".format( + about["__github__"], + about["__version__"], + "src", + fn, + linespec, + ) def remove_tabs_js(app: "Sphinx", exc: Exception) -> None: diff --git a/src/doctest_docutils.py b/src/doctest_docutils.py index 064ec1b..46e4aca 100644 --- a/src/doctest_docutils.py +++ b/src/doctest_docutils.py @@ -83,7 +83,7 @@ def run(self) -> t.List[Node]: test = code code = doctestopt_re.sub("", code) nodetype: t.Type[TextElement] = nodes.literal_block - if self.name in ("testsetup", "testcleanup") or "hide" in self.options: + if self.name in {"testsetup", "testcleanup"} or "hide" in self.options: nodetype = nodes.comment if self.arguments: groups = [x.strip() for x in self.arguments[0].split(",")] @@ -194,7 +194,7 @@ def setup() -> t.Dict[str, t.Any]: class DocTestFinderNameDoesNotExist(ValueError): """Raised with doctest lookup name not provided.""" - def __init__(self, string: str): + def __init__(self, string: str) -> None: return super().__init__( "DocTestFinder.find: name must be given " f"when string.__name__ doesn't exist: {type(string)!r}", @@ -213,7 +213,7 @@ def __init__( self, verbose: bool = False, parser: "doctest.DocTestParser" = parser, - ): + ) -> None: """Create a new doctest finder. The optional argument `parser` specifies a class or function that should be used @@ -279,7 +279,7 @@ def _find( ) -> None: """Find tests for the given string, and add them to `tests`.""" if self._verbose: - print("Finding tests in %s" % name) + pass # If we've already processed this string, then ignore it. if id(string) in seen: @@ -388,7 +388,7 @@ def _from_module( # Type ignored because this is a private function. return t.cast( bool, - super()._from_module(module, object), # type:ignore[misc] # NOQA: A002 + super()._from_module(module, object), # type:ignore[misc] ) else: # pragma: no cover @@ -439,7 +439,7 @@ def testdocutils( global master if package and not module_relative: - raise TestDocutilsPackageRelativeError() + raise TestDocutilsPackageRelativeError # Keep the absolute file paths. This is needed for Include directies to work. # The absolute path will be applied to source_path when creating the docutils doc. @@ -554,7 +554,7 @@ def _test() -> int: if args.fail_fast: options |= doctest.FAIL_FAST for filename in testfiles: - if filename.endswith(".rst") or filename.endswith(".md") or args.docutils: + if filename.endswith((".rst", ".md")) or args.docutils: failures, _ = testdocutils( filename, module_relative=False, diff --git a/src/linkify_issues.py b/src/linkify_issues.py index 2895685..b676d6b 100644 --- a/src/linkify_issues.py +++ b/src/linkify_issues.py @@ -30,14 +30,13 @@ def apply(self) -> None: assert issue_re.groups == 1 def condition(node: nodes.Node) -> bool: - cond = ( + return ( isinstance(node, nodes.Text) and len(re.findall(issue_re, node.astext())) > 0 ) and not isinstance( node.parent, (nodes.literal, nodes.FixedTextElement, nodes.reference), ) - return cond for node in findall(self.document)(condition): text = node.astext() diff --git a/src/pytest_doctest_docutils.py b/src/pytest_doctest_docutils.py index a98e97d..d8741a5 100644 --- a/src/pytest_doctest_docutils.py +++ b/src/pytest_doctest_docutils.py @@ -100,7 +100,7 @@ def _is_doctest( path: pathlib.Path, parent: pytest.Collector, ) -> bool: - if path.suffix in (".rst", ".md") and parent.session.isinitpath(path): + if path.suffix in {".rst", ".md"} and parent.session.isinitpath(path): return True globs = config.getoption("doctestglob") or ["*.rst", "*.md"] return any(path.match(path_pattern=glob) for glob in globs) diff --git a/tests/conftest.py b/tests/conftest.py index ca7a584..8958962 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -33,12 +33,12 @@ def __call__( ... -@pytest.fixture(scope="function") +@pytest.fixture() def make_app_params( request: pytest.FixtureRequest, app_params: AppParams, tmp_path: pathlib.Path, -) -> t.Generator[t.Callable[[t.Any], AppParams], None, None]: +) -> t.Callable[[t.Any], AppParams]: """Return Sphinx App factory, accepts custom params.""" def fn( @@ -73,4 +73,4 @@ def fn( return args, kws - yield fn + return fn