Skip to content

Commit

Permalink
refactor!(ruff): Run all automated fixes as of ruff 0.3.4
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
tony committed Mar 24, 2024
1 parent 464fb3c commit 9afc249
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
15 changes: 7 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions src/doctest_docutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(",")]
Expand Down Expand Up @@ -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}",
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/linkify_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_doctest_docutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -73,4 +73,4 @@ def fn(

return args, kws

yield fn
return fn

0 comments on commit 9afc249

Please sign in to comment.