Skip to content

Commit

Permalink
[pylint] Re-enable consider-using-dict-items
Browse files Browse the repository at this point in the history
Signed-off-by: Ponnuvel Palaniyappan <[email protected]>
  • Loading branch information
pponnuvel authored and TurboTurtle committed Aug 2, 2024
1 parent fb4cbd8 commit e88916f
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 58 deletions.
3 changes: 1 addition & 2 deletions plugins_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ def add_all_items(method, dest, wrapopen=r'\(', wrapclose=r'\)'):
if (len(sys.argv) > 1) and (sys.argv[1] == "csv"):
print("plugin;url;distros;profiles;packages;copyspecs;forbidden;commands;"
"service_status;journals;env_vars")
for plugname in plugs_data.keys():
plugin = plugs_data[plugname]
for plugname, plugin in plugs_data.items():
# determine max number of lines - usually
# "max(len(copyspec),len(commands))"
# ignore 'sourcecode' key as it
Expand Down
1 change: 0 additions & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ disable=
W0107, # unnecessary-pass
W0718, # broad-exception-caught
W0102, # dangerous-default-value
C0206, # consider-using-dict-items
W0221, # arguments-differ
W3101, # missing-timeout
C0201, # consider-iterating-dictionary
Expand Down
12 changes: 6 additions & 6 deletions sos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ def __init__(self, args):
raise
# build the top-level parser
_com_string = ''
for com in self._components:
aliases = self._components[com][1]
for com, value in self._components.items():
aliases = value[1]
aliases.insert(0, com)
_com = ', '.join(aliases)
desc = self._components[com][0].desc
desc = value[0].desc
_com_string += (f"\t{_com:<30}{desc}\n")
usage_string = ("%(prog)s <component> [options]\n\n"
"Available components:\n")
Expand All @@ -101,16 +101,16 @@ def __init__(self, args):
# now build the parser for each component.
# this needs to be done here, as otherwise --help will be unavailable
# for the component subparsers
for comp in self._components:
for comp, value in self._components.items():
_com_subparser = self.subparsers.add_parser(
comp,
aliases=self._components[comp][1],
aliases=value[1],
prog=f"sos {comp}"
)
_com_subparser.usage = f"sos {comp} [options]"
_com_subparser.register('action', 'extend', SosListOption)
self._add_common_options(_com_subparser)
self._components[comp][0].add_parser_options(parser=_com_subparser)
value[0].add_parser_options(parser=_com_subparser)
_com_subparser.set_defaults(component=comp)
self.args = self.parser.parse_args(self.cmdline)
self._init_component()
Expand Down
6 changes: 2 additions & 4 deletions sos/cleaner/mappings/hostname_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,10 @@ def load_domains_from_map(self):
_domain_to_inject = '.'.join(domain.split('.')[1:-1])
if not _domain_to_inject:
continue
for existing_domain in self.dataset.keys():
for existing_domain, value in self.dataset.items():
_existing = '.'.join(existing_domain.split('.')[:-1])
if _existing == _domain_to_inject:
_ob_domain = '.'.join(
self.dataset[existing_domain].split('.')[:-1]
)
_ob_domain = '.'.join(value.split('.')[:-1])
self._domains[_domain_to_inject] = _ob_domain
self.set_initial_counts()

Expand Down
4 changes: 2 additions & 2 deletions sos/cleaner/mappings/ip_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def get(self, ipaddr):
# an address with a CIDR notation and we're now looking for it without
# that notation
if '/' not in ipaddr:
for key in self.dataset.keys():
for key, value in self.dataset.items():
if key.startswith(ipaddr):
return self.dataset[key].split('/')[0]
return value.split('/')[0]

# fallback to the default map behavior of adding it fresh
return self.add(ipaddr)
Expand Down
3 changes: 1 addition & 2 deletions sos/cleaner/parsers/ipv6_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ def get_map_contents(self):
'version': self.mapping.version,
'networks': {}
}
for net in self.mapping.networks:
_net = self.mapping.networks[net]
for _, _net in self.mapping.networks.items():
_d['networks'][_net.original_address] = {
'obfuscated': _net.obfuscated_address,
'hosts': {}
Expand Down
12 changes: 6 additions & 6 deletions sos/collector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,9 @@ def display_help(cls, section):
section.add_text(
'The following help sections may be of further interest:\n'
)
for hsec in hsections:
for hsec, value in hsections.items():
section.add_text(
f"{' ':>8}{bold(hsec):<40}{hsections[hsec]:<30}",
f"{' ':>8}{bold(hsec):<40}{value:<30}",
newline=False
)

Expand Down Expand Up @@ -596,8 +596,8 @@ def verify_cluster_options(self):
if self.opts.cluster_options:
for opt in self.opts.cluster_options:
match = False
for clust in self.clusters:
for option in self.clusters[clust].options:
for clust, value in self.clusters.items():
for option in value.options:
if opt.name == option.name and opt.cluster == clust:
match = True
opt.value = self._validate_option(option, opt)
Expand Down Expand Up @@ -658,8 +658,8 @@ def list_options(self):
)

_opts = {}
for _cluster in self.clusters:
for opt in self.clusters[_cluster].options:
for _, value in self.clusters.items():
for opt in value.options:
if opt.name not in _opts.keys():
_opts[opt.name] = opt
else:
Expand Down
2 changes: 1 addition & 1 deletion sos/collector/clusters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def display_help(cls, section): # pylint: disable=too-many-branches

if cls.sos_plugin_options:
_opts = cls.sos_plugin_options
opts = ', '.join(f"{opt}={_opts[opt]}" for opt in _opts)
opts = ', '.join(f"{k}={v}" for k, v in _opts.items())
section.add_text(
f"Sets the following plugin options: {opts}",
newline=False
Expand Down
4 changes: 2 additions & 2 deletions sos/collector/clusters/ocp.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ def _build_dict(self, nodelist):
for node in nodelist:
_node = node.split()
nodes[_node[0]] = {}
for column in idx:
nodes[_node[0]][column] = _node[idx[column]]
for column, value in idx.items():
nodes[_node[0]][column] = _node[value]
return nodes

def set_transport_type(self):
Expand Down
11 changes: 4 additions & 7 deletions sos/help/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ def get_obj_for_topic(self):
'collector.transports.': self._get_collect_transport,
'collector.clusters.': self._get_collect_cluster,
}
for _sec in _help:
for _sec, value in _help.items():
if self.opts.topic.startswith(_sec):
cls = _help[_sec]()
cls = value()
break
return cls

Expand Down Expand Up @@ -209,11 +209,8 @@ def display_self_help(self):
'policies': 'How sos operates on different distributions'
}

for sect in sections:
avail_help.add_text(
f"\t{bold(sect):<36}{sections[sect]}",
newline=False
)
for sect, value in sections.items():
avail_help.add_text(f"\t{bold(sect):<36}{value}", newline=False)

self_help.display()

Expand Down
4 changes: 2 additions & 2 deletions sos/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ def __init__(self, arg_defaults={}, **kwargs):
for arg in self.arg_defaults:
setattr(self, arg, self.arg_defaults[arg])
# next, load any kwargs
for arg in kwargs.keys():
for arg, kwarg in kwargs.items():
self.arg_names.append(arg)
setattr(self, arg, kwargs[arg])
setattr(self, arg, kwarg)

@classmethod
def from_args(cls, args, arg_defaults={}):
Expand Down
11 changes: 4 additions & 7 deletions sos/policies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,8 @@ def display_help(cls, section):
seealso.add_text(
"For more information on distribution policies, see below\n"
)
for pol in pols:
seealso.add_text(
f"{' ':>8}{pol:<20}{pols[pol]:<30}",
newline=False
)
for pol, value in pols.items():
seealso.add_text(f"{' ':>8}{pol:<20}{value:<30}", newline=False)

def display_results(self, archive, directory, checksum, archivestat=None,
map_file=None):
Expand Down Expand Up @@ -523,9 +520,9 @@ def find_preset(self, preset):
:returns: a matching PresetProfile.
"""
# FIXME: allow fuzzy matching?
for match in self.presets.keys():
for match, value in self.presets.items():
if match == preset:
return self.presets[match]
return value

return None

Expand Down
11 changes: 5 additions & 6 deletions sos/policies/distros/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,10 @@ def display_distro_help(cls, section):
),
newline=False
)
for preset in _pol.presets:
_preset = _pol.presets[preset]
_opts = ' '.join(_preset.opts.to_args())
for preset, value in _pol.presets.items():
_opts = ' '.join(value.opts.to_args())
presec.add_text(
f"{' ':>8}{preset:<20}{_preset.desc:<45}{_opts:<30}",
f"{' ':>8}{preset:<20}{value.desc:<45}{_opts:<30}",
newline=False
)

Expand Down Expand Up @@ -291,8 +290,8 @@ def init_kernel_modules(self):
except IOError as err:
self.soslog.warning(f"Unable to read booted kernel config: {err}")

for builtin in config_strings:
if config_strings[builtin] in kconfigs:
for builtin, value in config_strings.items():
if value in kconfigs:
self.kernel_mods.append(builtin)

def join_sysroot(self, path):
Expand Down
4 changes: 2 additions & 2 deletions sos/policies/distros/redhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ def display_distro_help(cls, section):
'fedora': FedoraPolicy
}

for subc in subs:
for subc, value in subs.items():
subln = bold(f"policies.{subc}")
section.add_text(
f"{' ':>8}{subln:<35}{subs[subc].distro:<30}",
f"{' ':>8}{subln:<35}{value.distro:<30}",
newline=False
)

Expand Down
4 changes: 2 additions & 2 deletions sos/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ def display_help(cls, section):
'policies': 'How sos operates on different distributions'
}
helpln = ''
for ln in help_lines:
ssec.add_text(f"\t{ln:<36}{help_lines[ln]}", newline=False)
for ln, value in help_lines.items():
ssec.add_text(f"\t{ln:<36}{value}", newline=False)
ssec.add_text(helpln)

def print_header(self):
Expand Down
6 changes: 3 additions & 3 deletions sos/report/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def __init__(self, commons):

# add the default plugin opts
self.options.update(self.get_default_plugin_opts())
for popt in self.options:
for popt in self.options: # pylint: disable=consider-using-dict-items
self.options[popt].plugin = self.name()
for opt in self.option_list:
opt.plugin = self.name()
Expand Down Expand Up @@ -1630,11 +1630,11 @@ def generate_copyspec_tags(self):
"""After file collections have completed, retroactively generate
manifest entries to apply tags to files copied by generic copyspecs
"""
for file_regex in self.filetags:
for file_regex, tag in self.filetags.items():
manifest_data = {
'specification': file_regex,
'files_copied': [],
'tags': self.filetags[file_regex]
'tags': tag
}
matched_files = []
for cfile in self.copied_files:
Expand Down
6 changes: 3 additions & 3 deletions tests/sos_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,9 +823,9 @@ def setUp(self):
self.end_of_test_case = False
self.sm = software_manager.manager.SoftwareManager()

for dist in self.packages:
if isinstance(self.packages[dist], str):
self.packages[dist] = [self.packages[dist]]
for dist, value in self.packages.items():
if isinstance(value, str):
self.packages[dist] = [value]

keys = self.packages.keys()
# allow for single declaration of packages for the RH family
Expand Down

0 comments on commit e88916f

Please sign in to comment.