Skip to content

Commit

Permalink
Linting: Aggressive ruff pass (ruff v0.3.4, #33)
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Mar 24, 2024
2 parents ddc0dab + 097a7ee commit 85ae469
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
17 changes: 17 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ issue on the tracker.

### Development

- Aggressive automated lint fixes via `ruff` (#33)

via ruff v0.3.4, all automated lint fixes, including unsafe and previews were applied:

```sh
ruff check --select ALL . --fix --unsafe-fixes --preview --show-fixes; ruff format .
```

Branches were treated with:

```sh
git rebase \
--strategy-option=theirs \
--exec 'poetry run ruff check --select ALL . --fix --unsafe-fixes --preview --show-fixes; poetry run ruff format .; git add src tests; git commit --amend --no-edit' \
origin/master
```

- poetry: 1.7.1 -> 1.8.1

See also: https://github.com/python-poetry/poetry/blob/1.8.1/CHANGELOG.md
Expand Down
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)
logger.info(f"Finding tests in {name}")

# 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 85ae469

Please sign in to comment.