Skip to content

Commit

Permalink
pylint: ensure variables are initialized
Browse files Browse the repository at this point in the history
pylint doesn't know that some functions may terminate execution, like,
AnsibleModule's fail_json, and assume that, depending on the code path,
some variables may not be initialized when used.

This change ensure that variables are always initialized independent of
the code path.
  • Loading branch information
rjeffman committed May 22, 2024
1 parent f53ca3a commit 52241fe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
10 changes: 4 additions & 6 deletions plugins/modules/ipaautomember.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,10 @@ def main():
commands = []

for name in names:
_type = None
inclusive_add, inclusive_del = [], []
exclusive_add, exclusive_del = [], []

# Make sure automember rule exists
res_find = find_automember(ansible_module, name, automember_type)

Expand Down Expand Up @@ -495,26 +499,20 @@ def main():
transform_conditions(inclusive),
res_find.get("automemberinclusiveregex", [])
)
else:
inclusive_add, inclusive_del = [], []

if exclusive is not None:
exclusive_add, exclusive_del = gen_add_del_lists(
transform_conditions(exclusive),
res_find.get("automemberexclusiveregex", [])
)
else:
exclusive_add, exclusive_del = [], []

elif action == "member":
if res_find is None:
ansible_module.fail_json(
msg="No automember '%s'" % name)

inclusive_add = transform_conditions(inclusive or [])
inclusive_del = []
exclusive_add = transform_conditions(exclusive or [])
exclusive_del = []

for _inclusive in inclusive_add:
key, regex = _inclusive.split("=", 1)
Expand Down
2 changes: 2 additions & 0 deletions plugins/modules/ipadnsforwardzone.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ def main():
operation = "add"

invalid = []
wants_enable = False

if state in ["enabled", "disabled"]:
if action == "member":
ansible_module.fail_json(
Expand Down
2 changes: 2 additions & 0 deletions plugins/modules/ipadnsrecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,8 @@ def main():

res_find = find_dnsrecord(ansible_module, zone_name, name)

cmds = []

if state == 'present':
cmds = define_commands_for_present_state(
ansible_module, zone_name, entry, res_find)
Expand Down

0 comments on commit 52241fe

Please sign in to comment.