Skip to content

Commit b85d6e2

Browse files
MNT: Apply ruff/Pylint rule PLR6201
Use a set literal when testing for membership
1 parent 0c21896 commit b85d6e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+226
-226
lines changed

benchmarks/benchmarks/bench_ufunc_strides.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def time_unary(self, ufunc, stride_in, stride_out, dtype):
101101

102102
class UnaryFP(_AbstractUnary):
103103
params = [[uf for uf in UFUNCS_UNARY
104-
if uf not in (np.invert, np.bitwise_count)],
104+
if uf not in {np.invert, np.bitwise_count}],
105105
[1, 4],
106106
[1, 2],
107107
['e', 'f', 'd']]

doc/neps/tools/build_index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def nep_metadata():
5454
'(note that — here is a special, elongated dash). Got: '
5555
f' {tags["Title"]!r}')
5656

57-
if tags['Status'] in ('Accepted', 'Rejected', 'Withdrawn'):
57+
if tags['Status'] in {'Accepted', 'Rejected', 'Withdrawn'}:
5858
if 'Resolution' not in tags:
5959
raise RuntimeError(
6060
f'NEP {nr} is Accepted/Rejected/Withdrawn but '

numpy/_array_api_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def default_dtypes(self, *, device=None):
171171
'indexing': numpy.int64}
172172
173173
"""
174-
if device not in ["cpu", None]:
174+
if device not in {"cpu", None}:
175175
raise ValueError(
176176
'Device not understood. Only "cpu" is allowed, but received:'
177177
f' {device}'
@@ -238,7 +238,7 @@ def dtypes(self, *, device=None, kind=None):
238238
'int64': numpy.int64}
239239
240240
"""
241-
if device not in ["cpu", None]:
241+
if device not in {"cpu", None}:
242242
raise ValueError(
243243
'Device not understood. Only "cpu" is allowed, but received:'
244244
f' {device}'

numpy/_build_utils/tempita/_tempita.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ def parse_expr(tokens, name, context=()):
796796
name=name,
797797
)
798798
return ("py", pos, expr), tokens[1:]
799-
elif expr in ("continue", "break"):
799+
elif expr in {"continue", "break"}:
800800
if "for" not in context:
801801
raise TemplateError("continue outside of for loop", position=pos, name=name)
802802
return (expr, pos), tokens[1:]
@@ -806,9 +806,9 @@ def parse_expr(tokens, name, context=()):
806806
raise TemplateError(
807807
"%s outside of an if block" % expr.split()[0], position=pos, name=name
808808
)
809-
elif expr in ("if", "elif", "for"):
809+
elif expr in {"if", "elif", "for"}:
810810
raise TemplateError("%s with no expression" % expr, position=pos, name=name)
811-
elif expr in ("endif", "endfor", "enddef"):
811+
elif expr in {"endif", "endfor", "enddef"}:
812812
raise TemplateError("Unexpected %s" % expr, position=pos, name=name)
813813
elif expr.startswith("for "):
814814
return parse_for(tokens, name, context)
@@ -1038,7 +1038,7 @@ def get_token(pos=False):
10381038
elif (
10391039
not nest_count
10401040
and tok_type == tokenize.OP
1041-
and tok_string in ("(", "[", "{")
1041+
and tok_string in {"(", "[", "{"}
10421042
):
10431043
nest_type = tok_string
10441044
nest_count = 1

numpy/_core/_dtype.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def _scalar_str(dtype, short):
150150

151151
elif np.issubdtype(dtype, np.number):
152152
# Short repr with endianness, like '<f8'
153-
if short or dtype.byteorder not in ('=', '|'):
153+
if short or dtype.byteorder not in {'=', '|'}:
154154
return "'%s%c%d'" % (byteorder, dtype.kind, dtype.itemsize)
155155

156156
# Longer repr, like 'float64'
@@ -361,7 +361,7 @@ def _name_get(dtype):
361361
name += f"{dtype.itemsize * 8}"
362362

363363
# append metadata to datetimes
364-
if dtype.type in (np.datetime64, np.timedelta64):
364+
if dtype.type in {np.datetime64, np.timedelta64}:
365365
name += _datetime_metadata_str(dtype)
366366

367367
return name

numpy/_core/_internal.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _makenames_list(adict, align):
3030

3131
for fname, obj in adict.items():
3232
n = len(obj)
33-
if not isinstance(obj, tuple) or n not in (2, 3):
33+
if not isinstance(obj, tuple) or n not in {2, 3}:
3434
raise ValueError("entry not a 2- or 3- tuple")
3535
if n > 2 and obj[2] == fname:
3636
continue
@@ -187,7 +187,7 @@ def _commastring(astr):
187187
(order1, order2))
188188
order = order1
189189

190-
if order in ('|', '=', _nbo):
190+
if order in {'|', '=', _nbo}:
191191
order = ''
192192
dtype = order + dtype
193193
if repeats == '':
@@ -694,14 +694,14 @@ def __dtype_from_pep3118(stream, is_subdtype):
694694
shape = tuple(map(int, shape.split(',')))
695695

696696
# Byte order
697-
if stream.next in ('@', '=', '<', '>', '^', '!'):
697+
if stream.next in {'@', '=', '<', '>', '^', '!'}:
698698
byteorder = stream.advance(1)
699699
if byteorder == '!':
700700
byteorder = '>'
701701
stream.byteorder = byteorder
702702

703703
# Byte order characters also control native vs. standard type sizes
704-
if stream.byteorder in ('@', '^'):
704+
if stream.byteorder in {'@', '^'}:
705705
type_map = _pep3118_native_map
706706
type_map_chars = _pep3118_native_typechars
707707
else:

numpy/_core/_type_aliases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"complex": set(), "others": set()}
9898

9999
for type_info in typeinfo.values():
100-
if type_info.kind in ["M", "m"]: # exclude timedelta and datetime
100+
if type_info.kind in {"M", "m"}: # exclude timedelta and datetime
101101
continue
102102

103103
concrete_type = type_info.type

numpy/_core/arrayprint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def _make_options_dict(precision=None, threshold=None, edgeitems=None,
6666
raise ValueError("floatmode option must be one of " +
6767
", ".join(f'"{m}"' for m in modes))
6868

69-
if sign not in [None, '-', '+', ' ']:
69+
if sign not in {None, '-', '+', ' '}:
7070
raise ValueError("sign option must be one of ' ', '+', or '-'")
7171

7272
if legacy is False:
@@ -1048,7 +1048,7 @@ def fillFormat(self, data):
10481048
self.exp_size = -1
10491049
self.unique = unique
10501050

1051-
if self.floatmode in ['fixed', 'maxprec_equal']:
1051+
if self.floatmode in {'fixed', 'maxprec_equal'}:
10521052
self.precision = self.min_digits = self.pad_right
10531053
self.trim = 'k'
10541054
else:

numpy/_core/einsumfunc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ def einsum_path(*operands, optimize='greedy', einsum_call=False):
912912
# For broadcasting cases we always want the largest dim size
913913
if dimension_dict[char] == 1:
914914
dimension_dict[char] = dim
915-
elif dim not in (1, dimension_dict[char]):
915+
elif dim not in {1, dimension_dict[char]}:
916916
raise ValueError("Size of label '%s' for operand %d (%d) "
917917
"does not match previous terms (%d)."
918918
% (char, tnum, dimension_dict[char], dim))
@@ -944,7 +944,7 @@ def einsum_path(*operands, optimize='greedy', einsum_call=False):
944944
path = path_type[1:]
945945
elif (
946946
(path_type is False)
947-
or (len(input_list) in [1, 2])
947+
or (len(input_list) in {1, 2})
948948
or (indices == output_set)
949949
):
950950
# Nothing to be optimized, leave it to einsum

numpy/_core/memmap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def __new__(subtype, filename, dtype=uint8, mode='r+', offset=0,
250250
size = bytes // _dbytes
251251
shape = (size,)
252252
else:
253-
if type(shape) not in (tuple, list):
253+
if type(shape) not in {tuple, list}:
254254
try:
255255
shape = [operator.index(shape)]
256256
except TypeError:
@@ -262,7 +262,7 @@ def __new__(subtype, filename, dtype=uint8, mode='r+', offset=0,
262262

263263
bytes = int(offset + size * _dbytes)
264264

265-
if mode in ('w+', 'r+'):
265+
if mode in {'w+', 'r+'}:
266266
# gh-27723
267267
# if bytes == 0, we write out 1 byte to allow empty memmap.
268268
bytes = max(bytes, 1)

0 commit comments

Comments
 (0)