mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-07-25 00:44:42 +00:00
pylint: Fix warning 'unnecessary "else" after "return"'
Recent pylint versions warn against the use of an 'else' in a 'try-except' block if using a 'return' on the 'except' part is is the idom used by ansible-freeipa when retrieving IPA data objects. This change removes the usage of the 'else:' in such cases, and modify the templates so that new modules do not have the same issue in the future.
This commit is contained in:
@@ -121,7 +121,6 @@ class AutomountKey(IPAAnsibleModule):
|
||||
resp = self.ipa_command("automountkey_show", location, args)
|
||||
except ipalib_errors.NotFound:
|
||||
return None
|
||||
else:
|
||||
return resp.get("result")
|
||||
|
||||
def check_ipa_params(self):
|
||||
|
||||
@@ -92,7 +92,6 @@ class AutomountLocation(IPAAnsibleModule):
|
||||
)
|
||||
except ipalib_errors.NotFound:
|
||||
return None
|
||||
else:
|
||||
return response.get("result", None)
|
||||
|
||||
def check_ipa_params(self):
|
||||
|
||||
@@ -126,7 +126,6 @@ class AutomountMap(IPAAnsibleModule):
|
||||
)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
return None
|
||||
else:
|
||||
return response["result"]
|
||||
|
||||
def get_indirect_map_keys(self, location, name):
|
||||
|
||||
@@ -358,7 +358,6 @@ def get_netbios_name(module):
|
||||
_result = module.ipa_command_no_name("trustconfig_show", {"all": True})
|
||||
except Exception: # pylint: disable=broad-except
|
||||
return None
|
||||
else:
|
||||
return _result["result"]["ipantflatname"][0]
|
||||
|
||||
|
||||
|
||||
@@ -134,7 +134,6 @@ def find_delegation(module, name):
|
||||
except Exception: # pylint: disable=broad-except
|
||||
# An exception is raised if delegation name is not found.
|
||||
return None
|
||||
else:
|
||||
return _result["result"]
|
||||
|
||||
|
||||
|
||||
@@ -157,7 +157,6 @@ def find_idrange(module, name):
|
||||
except Exception: # pylint: disable=broad-except
|
||||
# An exception is raised if idrange name is not found.
|
||||
return None
|
||||
else:
|
||||
return _result["result"]
|
||||
|
||||
|
||||
|
||||
@@ -141,7 +141,6 @@ def find_idview(module, name):
|
||||
except Exception: # pylint: disable=broad-except
|
||||
# An exception is raised if idview name is not found.
|
||||
return None
|
||||
else:
|
||||
return _result["result"]
|
||||
|
||||
|
||||
|
||||
@@ -86,7 +86,6 @@ def find_location(module, name):
|
||||
except Exception: # pylint: disable=broad-except
|
||||
# An exception is raised if location name is not found.
|
||||
return None
|
||||
else:
|
||||
return _result["result"]
|
||||
|
||||
|
||||
|
||||
@@ -164,7 +164,6 @@ def find_permission(module, name):
|
||||
except Exception: # pylint: disable=broad-except
|
||||
# An exception is raised if permission name is not found.
|
||||
return None
|
||||
else:
|
||||
return _result["result"]
|
||||
|
||||
|
||||
|
||||
@@ -138,7 +138,6 @@ def find_privilege(module, name):
|
||||
except Exception: # pylint: disable=broad-except
|
||||
# An exception is raised if privilege name is not found.
|
||||
return None
|
||||
else:
|
||||
return _result["result"]
|
||||
|
||||
|
||||
|
||||
@@ -143,7 +143,6 @@ def find_role(module, name):
|
||||
except Exception: # pylint: disable=broad-except
|
||||
# An exception is raised if role name is not found.
|
||||
return None
|
||||
else:
|
||||
return _result["result"]
|
||||
|
||||
|
||||
|
||||
@@ -123,7 +123,6 @@ def find_selfservice(module, name):
|
||||
except Exception: # pylint: disable=broad-except
|
||||
# An exception is raised if selfservice name is not found.
|
||||
return None
|
||||
else:
|
||||
return _result["result"]
|
||||
|
||||
|
||||
|
||||
@@ -202,7 +202,6 @@ def find_server(module, name):
|
||||
except Exception: # pylint: disable=broad-except
|
||||
# An exception is raised if server name is not found.
|
||||
return None
|
||||
else:
|
||||
return _result["result"]
|
||||
|
||||
|
||||
@@ -218,7 +217,6 @@ def server_role_status(module, name):
|
||||
except Exception: # pylint: disable=broad-except
|
||||
# An exception is raised if server name is not found.
|
||||
return None
|
||||
else:
|
||||
return _result["result"][0]
|
||||
|
||||
|
||||
|
||||
@@ -145,7 +145,6 @@ def find_servicedelegationrule(module, name):
|
||||
except Exception: # pylint: disable=broad-except
|
||||
# An exception is raised if servicedelegationrule name is not found.
|
||||
return None
|
||||
else:
|
||||
return _result["result"]
|
||||
|
||||
|
||||
|
||||
@@ -121,7 +121,6 @@ def find_servicedelegationtarget(module, name):
|
||||
except Exception: # pylint: disable=broad-except
|
||||
# An exception is raised if servicedelegationtarget name is not found.
|
||||
return None
|
||||
else:
|
||||
return _result["result"]
|
||||
|
||||
|
||||
|
||||
@@ -122,7 +122,6 @@ def find_sudocmdgroup(module, name):
|
||||
_result = module.ipa_command("sudocmdgroup_show", name, args)
|
||||
except ipalib_errors.NotFound:
|
||||
return None
|
||||
else:
|
||||
return _result["result"]
|
||||
|
||||
|
||||
|
||||
@@ -62,7 +62,6 @@ def get_plugins_from_playbook(playbook):
|
||||
return []
|
||||
except yaml.parser.ParserError: # If not a YAML/JSON file.
|
||||
return []
|
||||
else:
|
||||
return data if data else []
|
||||
|
||||
data = load_playbook(playbook)
|
||||
|
||||
@@ -127,7 +127,6 @@ def find_$name(module, name):
|
||||
except Exception: # pylint: disable=broad-except
|
||||
# An exception is raised if $name name is not found.
|
||||
return None
|
||||
else:
|
||||
return _result["result"]
|
||||
|
||||
|
||||
|
||||
@@ -103,7 +103,6 @@ def find_$name(module, name):
|
||||
except Exception: # pylint: disable=broad-except
|
||||
# An exception is raised if $name name is not found.
|
||||
return None
|
||||
else:
|
||||
return _result["result"]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user