Enable Ruff perflint (PERF) rules

This commit is contained in:
Adam Turner
2024-01-04 04:01:52 +00:00
parent f547aefa15
commit 9d6667d8f7
4 changed files with 10 additions and 7 deletions

View File

@@ -128,7 +128,12 @@ select = [
# pandas-vet ('PD') # pandas-vet ('PD')
# Pandas is not used in Sphinx # Pandas is not used in Sphinx
# perflint ('PERF') # perflint ('PERF')
# NOT YET USED "PERF101", # Do not cast an iterable to `list` before iterating over it
"PERF102", # When using only the {subset} of a dict use the `{subset}()` method
# "PERF203", # `try`-`except` within a loop incurs performance overhead
# "PERF401", # Use a list comprehension to create a transformed list
"PERF402", # Use `list` or `list.copy` to create a copy of a list
"PERF403", # Use a dictionary comprehension instead of a for-loop
# pygrep-hooks ('PGH') # pygrep-hooks ('PGH')
"PGH", "PGH",
# flake8-pie ('PIE') # flake8-pie ('PIE')

View File

@@ -69,13 +69,12 @@ def app_params(request: Any, test_params: dict, shared_result: SharedResult,
# ##### process pytest.mark.sphinx # ##### process pytest.mark.sphinx
pargs = {} pargs: dict[int, Any] = {}
kwargs: dict[str, Any] = {} kwargs: dict[str, Any] = {}
# to avoid stacking positional args # to avoid stacking positional args
for info in reversed(list(request.node.iter_markers("sphinx"))): for info in reversed(list(request.node.iter_markers("sphinx"))):
for i, a in enumerate(info.args): pargs |= dict(enumerate(info.args))
pargs[i] = a
kwargs.update(info.kwargs) kwargs.update(info.kwargs)
args = [pargs[i] for i in sorted(pargs.keys())] args = [pargs[i] for i in sorted(pargs.keys())]

View File

@@ -26,8 +26,7 @@ def apidoc_params(request):
kwargs = {} kwargs = {}
for info in reversed(list(request.node.iter_markers("apidoc"))): for info in reversed(list(request.node.iter_markers("apidoc"))):
for i, a in enumerate(info.args): pargs |= dict(enumerate(info.args))
pargs[i] = a
kwargs.update(info.kwargs) kwargs.update(info.kwargs)
args = [pargs[i] for i in sorted(pargs.keys())] args = [pargs[i] for i in sorted(pargs.keys())]

View File

@@ -154,7 +154,7 @@ def test_get_items_summary(make_app, app_params):
def new_get_items(self, names, *args, **kwargs): def new_get_items(self, names, *args, **kwargs):
results = orig_get_items(self, names, *args, **kwargs) results = orig_get_items(self, names, *args, **kwargs)
for name, result in zip(names, results): for name, result in zip(names, results):
autosummary_items[name] = result autosummary_items[name] = result # NoQA: PERF403
return results return results
def handler(app, what, name, obj, options, lines): def handler(app, what, name, obj, options, lines):