Skip to content

Commit 621232a

Browse files
committed
Remove conversion of iterables into list objects
1 parent bad9127 commit 621232a

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

splunklib/data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def load(text, match=None):
9797
def load_attrs(element):
9898
if not hasattrs(element): return None
9999
attrs = record()
100-
for key, value in list(element.attrib.items()):
100+
for key, value in element.attrib.items():
101101
attrs[key] = value
102102
return attrs
103103

@@ -126,7 +126,7 @@ def load_elem(element, nametable=None):
126126
return name, attrs
127127
# Both attrs & value are complex, so merge the two dicts, resolving collisions.
128128
collision_keys = []
129-
for key, val in list(attrs.items()):
129+
for key, val in attrs.items():
130130
if key in value and key in collision_keys:
131131
value[key].append(val)
132132
elif key in value and key not in collision_keys:
@@ -242,7 +242,7 @@ def __getitem__(self, key):
242242
return dict.__getitem__(self, key)
243243
key += self.sep
244244
result = record()
245-
for k, v in list(self.items()):
245+
for k, v in self.items():
246246
if not k.startswith(key):
247247
continue
248248
suffix = k[len(key):]

splunklib/searchcommands/decorators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,21 +416,21 @@ def __init__(self, command):
416416
OrderedDict.__init__(self, ((option.name, item_class(command, option)) for (name, option) in definitions))
417417

418418
def __repr__(self):
419-
text = 'Option.View([' + ','.join([repr(item) for item in list(self.values())]) + '])'
419+
text = 'Option.View([' + ','.join([repr(item) for item in self.values()]) + '])'
420420
return text
421421

422422
def __str__(self):
423-
text = ' '.join([str(item) for item in list(self.values()) if item.is_set])
423+
text = ' '.join([str(item) for item in self.values() if item.is_set])
424424
return text
425425

426426
# region Methods
427427

428428
def get_missing(self):
429-
missing = [item.name for item in list(self.values()) if item.is_required and not item.is_set]
429+
missing = [item.name for item in self.values() if item.is_required and not item.is_set]
430430
return missing if len(missing) > 0 else None
431431

432432
def reset(self):
433-
for value in list(self.values()):
433+
for value in self.values():
434434
value.reset()
435435

436436
# endregion

tests/searchcommands/test_decorators.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,9 @@ def test_option(self):
353353

354354
options.reset()
355355
missing = options.get_missing()
356-
self.assertListEqual(missing, [option.name for option in list(options.values()) if option.is_required])
357-
self.assertListEqual(presets, [str(option) for option in list(options.values()) if option.value is not None])
358-
self.assertListEqual(presets, [str(option) for option in list(options.values()) if str(option) != option.name + '=None'])
356+
self.assertListEqual(missing, [option.name for option in options.values() if option.is_required])
357+
self.assertListEqual(presets, [str(option) for option in options.values() if option.value is not None])
358+
self.assertListEqual(presets, [str(option) for option in options.values() if str(option) != option.name + '=None'])
359359

360360
test_option_values = {
361361
validators.Boolean: ('0', 'non-boolean value'),
@@ -372,7 +372,7 @@ def test_option(self):
372372
validators.RegularExpression: ('\\s+', '(poorly formed regular expression'),
373373
validators.Set: ('bar', 'non-existent set entry')}
374374

375-
for option in list(options.values()):
375+
for option in options.values():
376376
validator = option.validator
377377

378378
if validator is None:
@@ -431,9 +431,9 @@ def test_option(self):
431431
self.maxDiff = None
432432

433433
tuplewrap = lambda x: x if isinstance(x, tuple) else (x,)
434-
invert = lambda x: {v: k for k, v in list(x.items())}
434+
invert = lambda x: {v: k for k, v in x.items()}
435435

436-
for x in list(command.options.values()):
436+
for x in command.options.values():
437437
# isinstance doesn't work for some reason
438438
if type(x.value).__name__ == 'Code':
439439
self.assertEqual(expected[x.name], x.value.source)

tests/searchcommands/test_internals_v1.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def fix_up(cls, command_class): pass
5353
command = TestCommandLineParserCommand()
5454
CommandLineParser.parse(command, options)
5555

56-
for option in list(command.options.values()):
56+
for option in command.options.values():
5757
if option.name in ['logging_configuration', 'logging_level', 'record', 'show_configuration']:
5858
self.assertFalse(option.is_set)
5959
continue
@@ -70,7 +70,7 @@ def fix_up(cls, command_class): pass
7070
command = TestCommandLineParserCommand()
7171
CommandLineParser.parse(command, options + fieldnames)
7272

73-
for option in list(command.options.values()):
73+
for option in command.options.values():
7474
if option.name in ['logging_configuration', 'logging_level', 'record', 'show_configuration']:
7575
self.assertFalse(option.is_set)
7676
continue
@@ -85,7 +85,7 @@ def fix_up(cls, command_class): pass
8585
command = TestCommandLineParserCommand()
8686
CommandLineParser.parse(command, ['required_option=true'] + fieldnames)
8787

88-
for option in list(command.options.values()):
88+
for option in command.options.values():
8989
if option.name in ['unnecessary_option', 'logging_configuration', 'logging_level', 'record',
9090
'show_configuration']:
9191
self.assertFalse(option.is_set)

tests/searchcommands/test_internals_v2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_record_writer_with_random_data(self, save_recording=False):
157157

158158
test_data['metrics'] = metrics
159159

160-
for name, metric in list(metrics.items()):
160+
for name, metric in metrics.items():
161161
writer.write_metric(name, metric)
162162

163163
self.assertEqual(writer._chunk_count, 0)
@@ -172,8 +172,8 @@ def test_record_writer_with_random_data(self, save_recording=False):
172172
self.assertListEqual(writer._inspector['messages'], messages)
173173

174174
self.assertDictEqual(
175-
dict(k_v for k_v in list(writer._inspector.items()) if k_v[0].startswith('metric.')),
176-
dict(('metric.' + k_v1[0], k_v1[1]) for k_v1 in list(metrics.items())))
175+
dict(k_v for k_v in writer._inspector.items() if k_v[0].startswith('metric.')),
176+
dict(('metric.' + k_v1[0], k_v1[1]) for k_v1 in metrics.items()))
177177

178178
writer.flush(finished=True)
179179

tests/test_conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_confs(self):
8787
testlib.tmpname(): testlib.tmpname()}
8888
stanza.submit(values)
8989
stanza.refresh()
90-
for key, value in list(values.items()):
90+
for key, value in values.items():
9191
self.assertTrue(key in stanza)
9292
self.assertEqual(value, stanza[key])
9393

tests/test_input.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def setUp(self):
200200

201201
def tearDown(self):
202202
super().tearDown()
203-
for entity in list(self._test_entities.values()):
203+
for entity in self._test_entities.values():
204204
try:
205205
self.service.inputs.delete(
206206
kind=entity.kind,
@@ -231,7 +231,7 @@ def test_lists_modular_inputs(self):
231231

232232
def test_create(self):
233233
inputs = self.service.inputs
234-
for entity in list(self._test_entities.values()):
234+
for entity in self._test_entities.values():
235235
self.check_entity(entity)
236236
self.assertTrue(isinstance(entity, client.Input))
237237

@@ -242,7 +242,7 @@ def test_get_kind_list(self):
242242

243243
def test_read(self):
244244
inputs = self.service.inputs
245-
for this_entity in list(self._test_entities.values()):
245+
for this_entity in self._test_entities.values():
246246
kind, name = this_entity.kind, this_entity.name
247247
read_entity = inputs[name, kind]
248248
self.assertEqual(this_entity.kind, read_entity.kind)
@@ -258,7 +258,7 @@ def test_read_indiviually(self):
258258

259259
def test_update(self):
260260
inputs = self.service.inputs
261-
for entity in list(self._test_entities.values()):
261+
for entity in self._test_entities.values():
262262
kind, name = entity.kind, entity.name
263263
kwargs = {'host': 'foo'}
264264
entity.update(**kwargs)
@@ -269,7 +269,7 @@ def test_update(self):
269269
def test_delete(self):
270270
inputs = self.service.inputs
271271
remaining = len(self._test_entities) - 1
272-
for input_entity in list(self._test_entities.values()):
272+
for input_entity in self._test_entities.values():
273273
name = input_entity.name
274274
kind = input_entity.kind
275275
self.assertTrue(name in inputs)

0 commit comments

Comments
 (0)