Skip to content

Commit 73f8bd0

Browse files
authored
Merge pull request numpy#28970 from DimitriPapadopoulos/PERF
MNT: Enforce ruff/Perflint rules (PERF)
2 parents bd5cb2a + c56f86d commit 73f8bd0

File tree

7 files changed

+36
-35
lines changed

7 files changed

+36
-35
lines changed

benchmarks/benchmarks/bench_ufunc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def setup(self, ufuncname):
5353
except AttributeError:
5454
raise NotImplementedError
5555
self.args = []
56-
for _, aarg in get_squares_().items():
56+
for aarg in get_squares_().values():
5757
arg = (aarg,) * 1 # no nin
5858
try:
5959
self.afdn(*arg)
@@ -100,7 +100,7 @@ def setup(self, ufuncname):
100100
except AttributeError:
101101
raise NotImplementedError
102102
self.args = []
103-
for _, aarg in get_squares_().items():
103+
for aarg in get_squares_().values():
104104
arg = (aarg,) * self.ufn.nin
105105
try:
106106
self.ufn(*arg)

numpy/_core/code_generators/genapi.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,7 @@ def _key(x):
466466
def merge_api_dicts(dicts):
467467
ret = {}
468468
for d in dicts:
469-
for k, v in d.items():
470-
ret[k] = v
469+
ret.update(d)
471470

472471
return ret
473472

numpy/f2py/func2subr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def var2fixfortran(vars, a, fa=None, f90mode=None):
7777

7878
def useiso_c_binding(rout):
7979
useisoc = False
80-
for key, value in rout['vars'].items():
80+
for value in rout['vars'].values():
8181
kind_value = value.get('kindselector', {}).get('kind')
8282
if kind_value in isoc_kindmap:
8383
return True

numpy/lib/introspect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def opt_func_info(func_name=None, signature=None):
8686
sig_pattern.search(c) or sig_pattern.search(dtype(c).name)
8787
for c in chars
8888
):
89-
matching_chars[chars] = targets
89+
matching_chars[chars] = targets # noqa: PERF403
9090
if matching_chars:
9191
matching_sigs[k] = matching_chars
9292
else:

numpy/ma/testutils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def assert_equal(actual, desired, err_msg=''):
121121
if not isinstance(actual, dict):
122122
raise AssertionError(repr(type(actual)))
123123
assert_equal(len(actual), len(desired), err_msg)
124-
for k, i in desired.items():
124+
for k in desired:
125125
if k not in actual:
126126
raise AssertionError(f"{k} not in {actual}")
127127
assert_equal(actual[k], desired[k], f'key={k!r}\n{err_msg}')
@@ -159,7 +159,7 @@ def fail_if_equal(actual, desired, err_msg='',):
159159
if not isinstance(actual, dict):
160160
raise AssertionError(repr(type(actual)))
161161
fail_if_equal(len(actual), len(desired), err_msg)
162-
for k, i in desired.items():
162+
for k in desired:
163163
if k not in actual:
164164
raise AssertionError(repr(k))
165165
fail_if_equal(actual[k], desired[k], f'key={k!r}\n{err_msg}')

numpy/testing/_private/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def assert_equal(actual, desired, err_msg='', verbose=True, *, strict=False):
364364
if not isinstance(actual, dict):
365365
raise AssertionError(repr(type(actual)))
366366
assert_equal(len(actual), len(desired), err_msg, verbose)
367-
for k, i in desired.items():
367+
for k in desired:
368368
if k not in actual:
369369
raise AssertionError(repr(k))
370370
assert_equal(actual[k], desired[k], f'key={k!r}\n{err_msg}',

ruff.toml

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,39 +32,41 @@ extend-select = [
3232
"FLY",
3333
"I",
3434
"PD",
35+
"PERF",
3536
"E",
3637
"W",
3738
"PGH",
3839
"PLE",
3940
"UP",
4041
]
4142
ignore = [
42-
"B006", # Do not use mutable data structures for argument defaults
43-
"B007", # Loop control variable not used within loop body
44-
"B011", # Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`
45-
"B023", # Function definition does not bind loop variable
46-
"B028", # No explicit `stacklevel` keyword argument found
47-
"B904", # Within an `except` clause distinguish raised exceptions from errors in exception handling
48-
"B905", #`zip()` without an explicit `strict=` parameter
49-
"C408", # Unnecessary `dict()` call (rewrite as a literal)
50-
"ISC002", # Implicitly concatenated string literals over multiple lines
51-
"PIE790", # Unnecessary `pass` statement
52-
"PD901", # Avoid using the generic variable name `df` for DataFrames
53-
"E241", # Multiple spaces after comma
54-
"E265", # Block comment should start with `# `
55-
"E266", # Too many leading `#` before block comment
56-
"E302", # TODO: Expected 2 blank lines, found 1
57-
"E402", # Module level import not at top of file
58-
"E712", # Avoid equality comparisons to `True` or `False`
59-
"E721", # TODO: Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance check
60-
"E731", # Do not assign a `lambda` expression, use a `def`
61-
"E741", # Ambiguous variable name
62-
"F403", # `from ... import *` used; unable to detect undefined names
63-
"F405", # may be undefined, or defined from star imports
64-
"F821", # Undefined name
65-
"F841", # Local variable is assigned to but never used
66-
"UP015", # Unnecessary mode argument
67-
"UP031", # TODO: Use format specifiers instead of percent format
43+
"B006", # Do not use mutable data structures for argument defaults
44+
"B007", # Loop control variable not used within loop body
45+
"B011", # Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`
46+
"B023", # Function definition does not bind loop variable
47+
"B028", # No explicit `stacklevel` keyword argument found
48+
"B904", # Within an `except` clause distinguish raised exceptions from errors in exception handling
49+
"B905", #`zip()` without an explicit `strict=` parameter
50+
"C408", # Unnecessary `dict()` call (rewrite as a literal)
51+
"ISC002", # Implicitly concatenated string literals over multiple lines
52+
"PIE790", # Unnecessary `pass` statement
53+
"PD901", # Avoid using the generic variable name `df` for DataFrames
54+
"PERF401", # Use a list comprehension to create a transformed list
55+
"E241", # Multiple spaces after comma
56+
"E265", # Block comment should start with `# `
57+
"E266", # Too many leading `#` before block comment
58+
"E302", # TODO: Expected 2 blank lines, found 1
59+
"E402", # Module level import not at top of file
60+
"E712", # Avoid equality comparisons to `True` or `False`
61+
"E721", # TODO: Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance check
62+
"E731", # Do not assign a `lambda` expression, use a `def`
63+
"E741", # Ambiguous variable name
64+
"F403", # `from ... import *` used; unable to detect undefined names
65+
"F405", # may be undefined, or defined from star imports
66+
"F821", # Undefined name
67+
"F841", # Local variable is assigned to but never used
68+
"UP015" , # Unnecessary mode argument
69+
"UP031", # TODO: Use format specifiers instead of percent format
6870
]
6971

7072
[lint.per-file-ignores]

0 commit comments

Comments
 (0)