Reduce code cognitive complexity

This commit is contained in:
Thaynã Moretti 2020-08-30 12:37:58 -03:00
parent 6f6f3cedd9
commit 49de0e520b

View file

@ -74,15 +74,22 @@ class Module(core.module.Module):
# https://bugs.python.org/issue32933
for line in f.readlines():
tmp = re.split(r"[:\s]+", line)
value = int(tmp[1])
if tmp[2] == "kB":
value = value * 1024
if tmp[2] == "mB":
value = value * 1024 * 1024
if tmp[2] == "gB":
value = value * 1024 * 1024 * 1024
value = self.__parse_value(tmp)
data[tmp[0]] = value
return data
def __parse_value(self, data):
value = int(data[1])
if data[2] == "kB":
value = value * 1024
if data[2] == "mB":
value = value * 1024 * 1024
if data[2] == "gB":
value = value * 1024 * 1024 * 1024
return value
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4