From 85286beb5b4da390e24ee35b9c3cd4c2455a1961 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Nov 13 2018 12:37:58 +0000 Subject: 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 Reviewed-By: Alexander Bokovoy --- diff --git a/install/share/wsgi.py b/install/share/wsgi.py index 06864b9..cbdb011 100644 --- a/install/share/wsgi.py +++ b/install/share/wsgi.py @@ -60,3 +60,4 @@ else: else: logger.error("IPA does not work with the threaded MPM, " "use the pre-fork MPM") + raise RuntimeError('threaded MPM detected') diff --git a/ipasetup.py.in b/ipasetup.py.in index 118829c..30c8c44 100644 --- a/ipasetup.py.in +++ b/ipasetup.py.in @@ -52,6 +52,7 @@ class build_py(setuptools_build_py): os.unlink(outfile) except OSError: pass + return None else: return setuptools_build_py.build_module(self, module, module_file, package) diff --git a/ipatests/pytest_ipa/integration/tasks.py b/ipatests/pytest_ipa/integration/tasks.py index 29774ca..e1d119d 100644 --- a/ipatests/pytest_ipa/integration/tasks.py +++ b/ipatests/pytest_ipa/integration/tasks.py @@ -1377,12 +1377,10 @@ def run_repeatedly(host, command, assert_zero_rc=True, test=None, 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. """ - ip = host.ip result = host.run_command(['ip', 'addr']) full_ip_regex = r'(?P%s/\d{1,2}) ' % re.escape(ip) @@ -1390,6 +1388,8 @@ def get_host_ip_with_hostmask(host): if match: return match.group('full_ip') + else: + return None def ldappasswd_user_change(user, oldpw, newpw, master): diff --git a/ipatests/test_cmdline/test_help.py b/ipatests/test_cmdline/test_help.py index d285036..c30f378 100644 --- a/ipatests/test_cmdline/test_help.py +++ b/ipatests/test_cmdline/test_help.py @@ -66,6 +66,8 @@ class CLITestContext: return False self.exception = exc_value return True + else: + return None def test_ipa_help(): diff --git a/ipatests/test_integration/test_topology.py b/ipatests/test_integration/test_topology.py index 02690a9..eb4ea89 100644 --- a/ipatests/test_integration/test_topology.py +++ b/ipatests/test_integration/test_topology.py @@ -25,6 +25,7 @@ def find_segment(master, replica): for segment in allsegments: if master.hostname in segment and replica.hostname in segment: return '-to-'.join(segment) + return None @pytest.mark.skipif(config.domain_level == 0, reason=reasoning) diff --git a/ipatests/test_ipalib/test_frontend.py b/ipatests/test_ipalib/test_frontend.py index 4f19cbb..7a51006 100644 --- a/ipatests/test_ipalib/test_frontend.py +++ b/ipatests/test_ipalib/test_frontend.py @@ -206,6 +206,8 @@ class test_Command(ClassChecker): def __call__(self, _, value): if value != self.name: return _('must equal %r') % self.name + else: + return None default_from = parameters.DefaultFrom( lambda arg: arg, diff --git a/ipatests/test_xmlrpc/test_baseldap_plugin.py b/ipatests/test_xmlrpc/test_baseldap_plugin.py index a7481ae..93fae68 100644 --- a/ipatests/test_xmlrpc/test_baseldap_plugin.py +++ b/ipatests/test_xmlrpc/test_baseldap_plugin.py @@ -187,13 +187,15 @@ def test_entry_to_dict(): class FakeSchema: def get_obj(self, type, name): if type != ldap.schema.AttributeType: - return + return None if name == 'binaryattr': return FakeAttributeType(name, '1.3.6.1.4.1.1466.115.121.1.40') elif name == 'textattr': return FakeAttributeType(name, '1.3.6.1.4.1.1466.115.121.1.15') elif name == 'dnattr': return FakeAttributeType(name, '1.3.6.1.4.1.1466.115.121.1.12') + else: + return None class FakeLDAPClient(ipaldap.LDAPClient): def __init__(self): diff --git a/ipatests/test_xmlrpc/test_certmap_plugin.py b/ipatests/test_xmlrpc/test_certmap_plugin.py index f973a6a..46d7dcd 100644 --- a/ipatests/test_xmlrpc/test_certmap_plugin.py +++ b/ipatests/test_xmlrpc/test_certmap_plugin.py @@ -272,9 +272,10 @@ class EWE: if self.expected and self.returned: assert_deepequal(self.expected, self.value) elif self.expected: - assert False, "Value expected but not provided" + raise AssertionError("Value expected but not provided") elif self.returned: - assert False, "Value provided but not expected" + raise AssertionError("Value provided but not expected") + return None def permissions_idfn(perms): diff --git a/ipatests/test_xmlrpc/test_dns_realmdomains_integration.py b/ipatests/test_xmlrpc/test_dns_realmdomains_integration.py index 4b244e0..70295c8 100644 --- a/ipatests/test_xmlrpc/test_dns_realmdomains_integration.py +++ b/ipatests/test_xmlrpc/test_dns_realmdomains_integration.py @@ -87,6 +87,8 @@ def assert_realmdomain_and_txt_record_not_present(response): api.Command['dnsrecord_show'](zone, u'_kerberos') except errors.NotFound: return True + else: + return False @pytest.mark.tier1