From d79b706c06e84e3c294994de7f62dbcadff90101 Mon Sep 17 00:00:00 2001 From: Harilou <1084430062@qq.com> Date: Tue, 14 Jan 2025 23:33:43 +0800 Subject: fix[doc.py]: path will be undefined (#84464) * fix[doc.py]: path will be undefined and a direct reference will throw an UnboundLocalError. If none of the files in files exists, path will be undefined and a direct reference will throw an UnboundLocalError. Repair function file parameter type annotation is inaccurate * Update changelogs/fragments/fix-cli-doc-path_undefined.yaml Co-authored-by: Sloane Hertel <19572925+s-hertel@users.noreply.github.com> --------- Co-authored-by: Brian Coca Co-authored-by: Sloane Hertel <19572925+s-hertel@users.noreply.github.com> --- changelogs/fragments/fix-cli-doc-path_undefined.yaml | 2 ++ lib/ansible/cli/doc.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/fix-cli-doc-path_undefined.yaml diff --git a/changelogs/fragments/fix-cli-doc-path_undefined.yaml b/changelogs/fragments/fix-cli-doc-path_undefined.yaml new file mode 100644 index 0000000000..9a62bf7738 --- /dev/null +++ b/changelogs/fragments/fix-cli-doc-path_undefined.yaml @@ -0,0 +1,2 @@ +bugfixes: +- ansible-doc - If none of the files in files exists, path will be undefined and a direct reference will throw an UnboundLocalError (https://github.com/ansible/ansible/pull/84464). diff --git a/lib/ansible/cli/doc.py b/lib/ansible/cli/doc.py index 52ec8a6c7b..6efe0319e5 100755 --- a/lib/ansible/cli/doc.py +++ b/lib/ansible/cli/doc.py @@ -104,7 +104,7 @@ class RoleMixin(object): """ Load and process the YAML for the first found of a set of role files :param str root: The root path to get the files from - :param str files: List of candidate file names in order of precedence + :param list files: List of candidate file names in order of precedence :param str role_name: The name of the role for which we want the argspec data. :param str collection: collection name or None in case of stand alone roles @@ -117,6 +117,7 @@ class RoleMixin(object): meta_path = os.path.join(root, 'meta') # Check all potential spec files + path = None for specfile in files: full_path = os.path.join(meta_path, specfile) if os.path.exists(full_path): -- cgit v1.2.3