Skip to content

Rewrite inline comprehensions as functions #128

@pederhan

Description

@pederhan

There are numerous places in the code where we use some sort of comprehension, be it dict, set, or list. This is fine from a performance standpoint, but not ideal from a code readability standpoint.

zabbix_managed_hosts: list[Host] = []
zabbix_manual_hosts: list[Host] = []
for host in zabbix_hosts.values():
if self.stop_event.is_set():
logger.debug("Told to stop. Breaking")
break
hostgroup_names = [group.name for group in host.groups]
if self.zabbix_config.hostgroup_manual in hostgroup_names:
zabbix_manual_hosts.append(host)
else:
zabbix_managed_hosts.append(host)
db_hostnames = set(db_hosts)
zabbix_hostnames = set(zabbix_hosts)
zabbix_managed_hostnames = {host.host for host in zabbix_managed_hosts}
zabbix_manual_hostnames = {host.host for host in zabbix_manual_hosts}

# Create dict of main interfaces only
zabbix_interfaces = {
i.type: i for i in zabbix_host.interfaces if i.main == 1
}

zproxies = self.api.get_proxies()
zabbix_proxies = {proxy.name: proxy for proxy in zproxies}

zabbix_proxy = [
proxy
for proxy in zabbix_proxies.values()
if proxy.proxyid == zabbix_proxy_id

It is not always well documented what these comprehension results are used for, and in certain cases we could benefit from refactoring these as functions. Maybe I am being too picky. Who knows.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions