Address inconsistent-return-statements

Pylint warns about inconsistent return statements when some paths of a
function return None implicitly. Make all implicit returns either
explicit or raise a proper exception.

See: https://pagure.io/freeipa/issue/7758
Signed-off-by: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
This commit is contained in:
Christian Heimes
2018-11-09 11:13:38 +01:00
parent 8944458d3c
commit 85286beb5b
9 changed files with 18 additions and 6 deletions

View File

@@ -60,3 +60,4 @@ else:
else: else:
logger.error("IPA does not work with the threaded MPM, " logger.error("IPA does not work with the threaded MPM, "
"use the pre-fork MPM") "use the pre-fork MPM")
raise RuntimeError('threaded MPM detected')

View File

@@ -52,6 +52,7 @@ class build_py(setuptools_build_py):
os.unlink(outfile) os.unlink(outfile)
except OSError: except OSError:
pass pass
return None
else: else:
return setuptools_build_py.build_module(self, module, return setuptools_build_py.build_module(self, module,
module_file, package) module_file, package)

View File

@@ -1377,12 +1377,10 @@ def run_repeatedly(host, command, assert_zero_rc=True, test=None,
def get_host_ip_with_hostmask(host): def get_host_ip_with_hostmask(host):
""" """Detects the IP of the host including the hostmask
Detects the IP of the host including the hostmask.
Returns None if the IP could not be detected. Returns None if the IP could not be detected.
""" """
ip = host.ip ip = host.ip
result = host.run_command(['ip', 'addr']) result = host.run_command(['ip', 'addr'])
full_ip_regex = r'(?P<full_ip>%s/\d{1,2}) ' % re.escape(ip) full_ip_regex = r'(?P<full_ip>%s/\d{1,2}) ' % re.escape(ip)
@@ -1390,6 +1388,8 @@ def get_host_ip_with_hostmask(host):
if match: if match:
return match.group('full_ip') return match.group('full_ip')
else:
return None
def ldappasswd_user_change(user, oldpw, newpw, master): def ldappasswd_user_change(user, oldpw, newpw, master):

View File

@@ -66,6 +66,8 @@ class CLITestContext:
return False return False
self.exception = exc_value self.exception = exc_value
return True return True
else:
return None
def test_ipa_help(): def test_ipa_help():

View File

@@ -25,6 +25,7 @@ def find_segment(master, replica):
for segment in allsegments: for segment in allsegments:
if master.hostname in segment and replica.hostname in segment: if master.hostname in segment and replica.hostname in segment:
return '-to-'.join(segment) return '-to-'.join(segment)
return None
@pytest.mark.skipif(config.domain_level == 0, reason=reasoning) @pytest.mark.skipif(config.domain_level == 0, reason=reasoning)

View File

@@ -206,6 +206,8 @@ class test_Command(ClassChecker):
def __call__(self, _, value): def __call__(self, _, value):
if value != self.name: if value != self.name:
return _('must equal %r') % self.name return _('must equal %r') % self.name
else:
return None
default_from = parameters.DefaultFrom( default_from = parameters.DefaultFrom(
lambda arg: arg, lambda arg: arg,

View File

@@ -187,13 +187,15 @@ def test_entry_to_dict():
class FakeSchema: class FakeSchema:
def get_obj(self, type, name): def get_obj(self, type, name):
if type != ldap.schema.AttributeType: if type != ldap.schema.AttributeType:
return return None
if name == 'binaryattr': if name == 'binaryattr':
return FakeAttributeType(name, '1.3.6.1.4.1.1466.115.121.1.40') return FakeAttributeType(name, '1.3.6.1.4.1.1466.115.121.1.40')
elif name == 'textattr': elif name == 'textattr':
return FakeAttributeType(name, '1.3.6.1.4.1.1466.115.121.1.15') return FakeAttributeType(name, '1.3.6.1.4.1.1466.115.121.1.15')
elif name == 'dnattr': elif name == 'dnattr':
return FakeAttributeType(name, '1.3.6.1.4.1.1466.115.121.1.12') return FakeAttributeType(name, '1.3.6.1.4.1.1466.115.121.1.12')
else:
return None
class FakeLDAPClient(ipaldap.LDAPClient): class FakeLDAPClient(ipaldap.LDAPClient):
def __init__(self): def __init__(self):

View File

@@ -272,9 +272,10 @@ class EWE:
if self.expected and self.returned: if self.expected and self.returned:
assert_deepequal(self.expected, self.value) assert_deepequal(self.expected, self.value)
elif self.expected: elif self.expected:
assert False, "Value expected but not provided" raise AssertionError("Value expected but not provided")
elif self.returned: elif self.returned:
assert False, "Value provided but not expected" raise AssertionError("Value provided but not expected")
return None
def permissions_idfn(perms): def permissions_idfn(perms):

View File

@@ -87,6 +87,8 @@ def assert_realmdomain_and_txt_record_not_present(response):
api.Command['dnsrecord_show'](zone, u'_kerberos') api.Command['dnsrecord_show'](zone, u'_kerberos')
except errors.NotFound: except errors.NotFound:
return True return True
else:
return False
@pytest.mark.tier1 @pytest.mark.tier1