Skip to content

Commit

Permalink
Remove conversion of iterables into list objects
Browse files Browse the repository at this point in the history
  • Loading branch information
maszyk99 committed Mar 4, 2024
1 parent bad9127 commit 621232a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions splunklib/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def load(text, match=None):
def load_attrs(element):
if not hasattrs(element): return None
attrs = record()
for key, value in list(element.attrib.items()):
for key, value in element.attrib.items():
attrs[key] = value
return attrs

Expand Down Expand Up @@ -126,7 +126,7 @@ def load_elem(element, nametable=None):
return name, attrs
# Both attrs & value are complex, so merge the two dicts, resolving collisions.
collision_keys = []
for key, val in list(attrs.items()):
for key, val in attrs.items():
if key in value and key in collision_keys:
value[key].append(val)
elif key in value and key not in collision_keys:
Expand Down Expand Up @@ -242,7 +242,7 @@ def __getitem__(self, key):
return dict.__getitem__(self, key)
key += self.sep
result = record()
for k, v in list(self.items()):
for k, v in self.items():
if not k.startswith(key):
continue
suffix = k[len(key):]
Expand Down
8 changes: 4 additions & 4 deletions splunklib/searchcommands/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,21 +416,21 @@ def __init__(self, command):
OrderedDict.__init__(self, ((option.name, item_class(command, option)) for (name, option) in definitions))

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

def __str__(self):
text = ' '.join([str(item) for item in list(self.values()) if item.is_set])
text = ' '.join([str(item) for item in self.values() if item.is_set])
return text

# region Methods

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

def reset(self):
for value in list(self.values()):
for value in self.values():
value.reset()

# endregion
Expand Down
12 changes: 6 additions & 6 deletions tests/searchcommands/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ def test_option(self):

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

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

for option in list(options.values()):
for option in options.values():
validator = option.validator

if validator is None:
Expand Down Expand Up @@ -431,9 +431,9 @@ def test_option(self):
self.maxDiff = None

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

for x in list(command.options.values()):
for x in command.options.values():
# isinstance doesn't work for some reason
if type(x.value).__name__ == 'Code':
self.assertEqual(expected[x.name], x.value.source)
Expand Down
6 changes: 3 additions & 3 deletions tests/searchcommands/test_internals_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def fix_up(cls, command_class): pass
command = TestCommandLineParserCommand()
CommandLineParser.parse(command, options)

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

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

for option in list(command.options.values()):
for option in command.options.values():
if option.name in ['unnecessary_option', 'logging_configuration', 'logging_level', 'record',
'show_configuration']:
self.assertFalse(option.is_set)
Expand Down
6 changes: 3 additions & 3 deletions tests/searchcommands/test_internals_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_record_writer_with_random_data(self, save_recording=False):

test_data['metrics'] = metrics

for name, metric in list(metrics.items()):
for name, metric in metrics.items():
writer.write_metric(name, metric)

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

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

writer.flush(finished=True)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_confs(self):
testlib.tmpname(): testlib.tmpname()}
stanza.submit(values)
stanza.refresh()
for key, value in list(values.items()):
for key, value in values.items():
self.assertTrue(key in stanza)
self.assertEqual(value, stanza[key])

Expand Down
10 changes: 5 additions & 5 deletions tests/test_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def setUp(self):

def tearDown(self):
super().tearDown()
for entity in list(self._test_entities.values()):
for entity in self._test_entities.values():
try:
self.service.inputs.delete(
kind=entity.kind,
Expand Down Expand Up @@ -231,7 +231,7 @@ def test_lists_modular_inputs(self):

def test_create(self):
inputs = self.service.inputs
for entity in list(self._test_entities.values()):
for entity in self._test_entities.values():
self.check_entity(entity)
self.assertTrue(isinstance(entity, client.Input))

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

def test_read(self):
inputs = self.service.inputs
for this_entity in list(self._test_entities.values()):
for this_entity in self._test_entities.values():
kind, name = this_entity.kind, this_entity.name
read_entity = inputs[name, kind]
self.assertEqual(this_entity.kind, read_entity.kind)
Expand All @@ -258,7 +258,7 @@ def test_read_indiviually(self):

def test_update(self):
inputs = self.service.inputs
for entity in list(self._test_entities.values()):
for entity in self._test_entities.values():
kind, name = entity.kind, entity.name
kwargs = {'host': 'foo'}
entity.update(**kwargs)
Expand All @@ -269,7 +269,7 @@ def test_update(self):
def test_delete(self):
inputs = self.service.inputs
remaining = len(self._test_entities) - 1
for input_entity in list(self._test_entities.values()):
for input_entity in self._test_entities.values():
name = input_entity.name
kind = input_entity.kind
self.assertTrue(name in inputs)
Expand Down

0 comments on commit 621232a

Please sign in to comment.