From 4f7318767c50e412b95f04ef911aa5cf53c5a360 Mon Sep 17 00:00:00 2001 From: danieleades <33452915+danieleades@users.noreply.github.com> Date: Sun, 17 Mar 2024 11:06:39 +0000 Subject: [PATCH] [lint] extend FURB lints (#12088) --- .ruff.toml | 25 ++----------------- sphinx/ext/napoleon/docstring.py | 6 ++--- sphinx/transforms/post_transforms/__init__.py | 3 ++- tests/test_builders/test_build_linkcheck.py | 2 +- 4 files changed, 7 insertions(+), 29 deletions(-) diff --git a/.ruff.toml b/.ruff.toml index 0d34a34b0..68c4ecb42 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -15,13 +15,10 @@ exclude = [ "doc/usage/extensions/example*.py", ] ignore = [ - # flake8-annotations "ANN401", # Dynamically typed expressions (typing.Any) are disallowed in `{name}` - # pycodestyle "E741", # Ambiguous variable name: `{name}` - # pyflakes "F841", # Local variable `{name}` is assigned to but never used - # pylint + "FURB101", # `open` and `read` should be replaced by `Path(...).read_text(...)` "PLC1901", # simplify truthy/falsey string comparisons "SIM102", # Use a single `if` statement instead of nested `if` statements "SIM108", # Use ternary operator `{contents}` instead of `if`-`else`-block @@ -127,25 +124,7 @@ select = [ # NOT YET USED # flynt ('FLY') # NOT YET USED - # refurb ('FURB') -# "FURB101", # `open` and `read` should be replaced by `Path({filename}).{suggestion}` - "FURB105", # Unnecessary empty string passed to `print` - "FURB113", # Use `{suggestion}` instead of repeatedly calling `{name}.append()` - "FURB118", # Use `operator.{operator}` instead of defining a function - "FURB131", # Prefer `clear` over deleting a full slice - "FURB132", # Use `{suggestion}` instead of check and `remove` - "FURB136", # Replace `if` expression with `{min_max}` call -# "FURB140", # Use `itertools.starmap` instead of the generator - "FURB145", # Prefer `copy` method over slicing - "FURB148", # `enumerate` value is unused, use `for x in range(len(y))` instead - "FURB152", # Replace `{literal}` with `math.{constant}` - "FURB161", # Use of `bin({existing}).count('1')` - "FURB163", # Prefer `math.{log_function}({arg})` over `math.log` with a redundant base - "FURB168", # Prefer `is` operator over `isinstance` to check if an object is `None` - "FURB169", # Compare the identities of `{object}` and `None` instead of their respective types - "FURB171", # Membership test against single-item container - "FURB177", # Prefer `Path.cwd()` over `Path().resolve()` for current-directory lookups - "FURB181", # Use of hashlib's `.digest().hex()` + "FURB", # refurb # flake8-logging-format ('G') "G001", # Logging statement uses `str.format` # "G002", # Logging statement uses `%` diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py index 446da1344..2ce3b2d42 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -7,6 +7,7 @@ import contextlib import inspect import re from functools import partial +from itertools import starmap from typing import TYPE_CHECKING, Any, Callable from sphinx.locale import _, __ @@ -1340,10 +1341,7 @@ class NumpyDocstring(GoogleDocstring): return [] # apply type aliases - items = [ - translate(func, description, role) - for func, description, role in items - ] + items = list(starmap(translate, items)) lines: list[str] = [] last_had_desc = True diff --git a/sphinx/transforms/post_transforms/__init__.py b/sphinx/transforms/post_transforms/__init__.py index 70c26d3a6..efb5272c1 100644 --- a/sphinx/transforms/post_transforms/__init__.py +++ b/sphinx/transforms/post_transforms/__init__.py @@ -3,6 +3,7 @@ from __future__ import annotations import re +from itertools import starmap from typing import TYPE_CHECKING, Any, cast from docutils import nodes @@ -155,7 +156,7 @@ class ReferencesResolver(SphinxPostTransform): def stringify(name: str, node: Element) -> str: reftitle = node.get('reftitle', node.astext()) return f':{name}:`{reftitle}`' - candidates = ' or '.join(stringify(name, role) for name, role in results) + candidates = ' or '.join(starmap(stringify, results)) logger.warning(__("more than one target found for 'any' cross-" 'reference %r: could be %s'), target, candidates, location=node) diff --git a/tests/test_builders/test_build_linkcheck.py b/tests/test_builders/test_build_linkcheck.py index 06f027b8c..a65be6c82 100644 --- a/tests/test_builders/test_build_linkcheck.py +++ b/tests/test_builders/test_build_linkcheck.py @@ -577,7 +577,7 @@ def test_linkcheck_allowed_redirects(app, warning): app.build() with open(app.outdir / 'output.json', encoding='utf-8') as fp: - rows = [json.loads(l) for l in fp.readlines()] + rows = [json.loads(l) for l in fp] assert len(rows) == 2 records = {row["uri"]: row for row in rows}