From b1d278a5958a81dbcd12184f3e5d638f1d948481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Mon, 8 Mar 2021 05:16:09 -0500 Subject: [PATCH] ansible-test: yamllint, check the assigment (#73583) Ensure `yamllint`'s `check_assignment()` correctly ignore the attribute assignment. Those don't have any `.id` attribute and will trigger an `AttributeError` exception. See: https://github.com/ansible/ansible/pull/73322 (cherry picked from commit 0a8d5c098367a58eaff10fd5b3868f099c1e17a7) --- .../ansible_test_yamllint_avoid_attribute_exception.yaml | 3 +++ test/lib/ansible_test/_data/sanity/yamllint/yamllinter.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/ansible_test_yamllint_avoid_attribute_exception.yaml diff --git a/changelogs/fragments/ansible_test_yamllint_avoid_attribute_exception.yaml b/changelogs/fragments/ansible_test_yamllint_avoid_attribute_exception.yaml new file mode 100644 index 00000000000..bd571d6cc6c --- /dev/null +++ b/changelogs/fragments/ansible_test_yamllint_avoid_attribute_exception.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- yamllint - do not raise an ``AttributeError`` if a value is assigned to a module attribute at the top of the module. diff --git a/test/lib/ansible_test/_data/sanity/yamllint/yamllinter.py b/test/lib/ansible_test/_data/sanity/yamllint/yamllinter.py index 933debe707a..c9cdc19ce15 100644 --- a/test/lib/ansible_test/_data/sanity/yamllint/yamllinter.py +++ b/test/lib/ansible_test/_data/sanity/yamllint/yamllinter.py @@ -180,7 +180,7 @@ class YamlChecker: def check_assignment(statement, doc_types=None): """Check the given statement for a documentation assignment.""" for target in statement.targets: - if isinstance(target, ast.Tuple): + if not isinstance(target, ast.Name): continue if doc_types and target.id not in doc_types: