[lint] extend FURB lints (#12088)

This commit is contained in:
danieleades
2024-03-17 11:06:39 +00:00
committed by GitHub
parent 22968d29f5
commit 4f7318767c
4 changed files with 7 additions and 29 deletions

View File

@@ -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 `%`

View File

@@ -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

View File

@@ -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)

View File

@@ -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}