core: refactor code quality issues

The following commit fixes a few code quality issues detected by DeepSource:
- Use literals instead of function calls to create data structure.
- Refactor unnecessary list comprehension.
- Simplify if statement.
- Refactor useless else block in the loop.

Signed-off-by: Aksh Gupta <akshgpt7@gmail.com>
pull/6306/head
Aksh Gupta 2021-03-19 18:45:26 +00:00 committed by Guillaume Abrioux
parent b01f16e835
commit a0bc5afe26
5 changed files with 28 additions and 10 deletions

18
.deepsource.toml 100644
View File

@ -0,0 +1,18 @@
version = 1
test_patterns = ["tests/**"]
exclude_patterns = [
"roles/**",
"profiles/**",
"infrastructure-playbooks/**",
"group_vars/**",
"contrib/**"
]
[[analyzers]]
name = "python"
enabled = true
[analyzers.meta]
runtime_version = "3.x.x"

View File

@ -179,8 +179,8 @@ class ConfigTemplateParser(ConfigParser.RawConfigParser):
_write_comments(section_name, optname=key) _write_comments(section_name, optname=key)
self._write_check(fp, key=key, value=value, self._write_check(fp, key=key, value=value,
section=section_bool) section=section_bool)
else:
fp.write("\n") fp.write("\n")
def _write_comments(section, optname=None): def _write_comments(section, optname=None):
comsect = self._comments.get(section, {}) comsect = self._comments.get(section, {})
@ -453,8 +453,8 @@ class ActionModule(ActionBase):
'data. Sections are case sensitive.' 'data. Sections are case sensitive.'
) )
raise errors.AnsibleModuleError(error_msg) raise errors.AnsibleModuleError(error_msg)
else:
config_object.close() config_object.close()
config_dict_new = {} config_dict_new = {}
config_defaults = config.defaults() config_defaults = config.defaults()
@ -665,7 +665,7 @@ class ActionModule(ActionBase):
return True, dict( return True, dict(
source=source, source=source,
dest=user_dest, dest=user_dest,
config_overrides=self._task.args.get('config_overrides', dict()), config_overrides=self._task.args.get('config_overrides', {}),
config_type=config_type, config_type=config_type,
searchpath=searchpath, searchpath=searchpath,
list_extend=list_extend, list_extend=list_extend,

View File

@ -14,7 +14,7 @@ class FilterModule(object):
''' IP addresses within IP ranges ''' ''' IP addresses within IP ranges '''
def ips_in_ranges(self, ip_addresses, ip_ranges): def ips_in_ranges(self, ip_addresses, ip_ranges):
ips_in_ranges = list() ips_in_ranges = []
for ip_addr in ip_addresses: for ip_addr in ip_addresses:
for ip_range in ip_ranges: for ip_range in ip_ranges:
if netaddr.IPAddress(ip_addr) in netaddr.IPNetwork(ip_range): if netaddr.IPAddress(ip_addr) in netaddr.IPNetwork(ip_range):

View File

@ -38,8 +38,8 @@ class TestNFSs(object):
cluster=cluster cluster=cluster
) )
output = host.check_output(cmd) output = host.check_output(cmd)
keys = [i for i in json.loads( keys = list(json.loads(
output)["servicemap"]["services"]["rgw-nfs"]["daemons"].keys()] output)["servicemap"]["services"]["rgw-nfs"]["daemons"].keys())
keys.remove('summary') keys.remove('summary')
daemons = json.loads(output)["servicemap"]["services"]["rgw-nfs"]["daemons"] daemons = json.loads(output)["servicemap"]["services"]["rgw-nfs"]["daemons"]
hostnames = [] hostnames = []

View File

@ -36,8 +36,8 @@ class TestRGWs(object):
cluster=cluster cluster=cluster
) )
output = host.check_output(cmd) output = host.check_output(cmd)
keys = [i for i in json.loads( keys = list(json.loads(
output)["servicemap"]["services"]["rgw"]["daemons"].keys()] output)["servicemap"]["services"]["rgw"]["daemons"].keys())
keys.remove('summary') keys.remove('summary')
daemons = json.loads(output)["servicemap"]["services"]["rgw"]["daemons"] daemons = json.loads(output)["servicemap"]["services"]["rgw"]["daemons"]
hostnames = [] hostnames = []