-
Notifications
You must be signed in to change notification settings - Fork 5
Rewrite inline comprehensions as functions #128
Description
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-auto-config/zabbix_auto_config/processing.py
Lines 1287 to 1303 in c351bcf
| 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} |
zabbix-auto-config/zabbix_auto_config/processing.py
Lines 1399 to 1402 in c351bcf
| # Create dict of main interfaces only | |
| zabbix_interfaces = { | |
| i.type: i for i in zabbix_host.interfaces if i.main == 1 | |
| } |
zabbix-auto-config/zabbix_auto_config/processing.py
Lines 1282 to 1283 in c351bcf
| zproxies = self.api.get_proxies() | |
| zabbix_proxies = {proxy.name: proxy for proxy in zproxies} |
zabbix-auto-config/zabbix_auto_config/processing.py
Lines 1361 to 1364 in c351bcf
| 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.