diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 278bb98538..3cd13bb307 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -63,7 +63,7 @@ repos: args: [--relative, --no-progress, --no-summary] name: Spell check with cspell - repo: https://github.com/sirosen/check-jsonschema - rev: 0.19.2 + rev: 0.20.0 hooks: - id: check-github-workflows - repo: https://github.com/pre-commit/pre-commit-hooks.git @@ -112,7 +112,7 @@ repos: hooks: - id: doc8 - repo: https://github.com/adrienverge/yamllint.git - rev: v1.28.0 + rev: v1.29.0 hooks: - id: yamllint exclude: > @@ -181,7 +181,7 @@ repos: plugins/.* )$ - repo: https://github.com/pycqa/pylint - rev: v2.15.9 + rev: v2.16.0b0 hooks: - id: pylint args: diff --git a/plugins/modules/fake_module.py b/plugins/modules/fake_module.py index 29e8dc0adb..141362e412 100644 --- a/plugins/modules/fake_module.py +++ b/plugins/modules/fake_module.py @@ -8,9 +8,9 @@ def main() -> None: """Return the module instance.""" return AnsibleModule( - argument_spec=dict( - data=dict(default=None), - path=dict(default=None, type=str), - file=dict(default=None, type=str), - ) + argument_spec={ + "data": {"default": None}, + "path": {"default": None}, + "file": {"default": None}, + } ) diff --git a/src/ansiblelint/utils.py b/src/ansiblelint/utils.py index aa71288bac..4054cab00b 100644 --- a/src/ansiblelint/utils.py +++ b/src/ansiblelint/utils.py @@ -300,7 +300,7 @@ def play_children( v = template( os.path.abspath(basedir), v, - dict(playbook_dir=PLAYBOOK_DIR or os.path.abspath(basedir)), + {"playbook_dir": PLAYBOOK_DIR or os.path.abspath(basedir)}, fail_on_undefined=False, ) return delegate_map[k](basedir, k, v, parent_type) @@ -523,7 +523,7 @@ def _look_for_role_files( def _kv_to_dict(v: str) -> dict[str, Any]: (command, args, kwargs) = tokenize(v) - return dict(__ansible_module__=command, __ansible_arguments__=args, **kwargs) + return {"__ansible_module__": command, "__ansible_arguments__": args, **kwargs} def _sanitize_task(task: dict[str, Any]) -> dict[str, Any]: @@ -564,10 +564,10 @@ def normalize_task_v2(task: dict[str, Any]) -> dict[str, Any]: if is_nested_task(task): _extract_ansible_parsed_keys_from_task(result, task, ansible_parsed_keys) # Add dummy action for block/always/rescue statements - result["action"] = dict( - __ansible_module__="block/always/rescue", - __ansible_module_original__="block/always/rescue", - ) + result["action"] = { + "__ansible_module__": "block/always/rescue", + "__ansible_module_original__": "block/always/rescue", + } return result @@ -604,9 +604,10 @@ def normalize_task_v2(task: dict[str, Any]) -> dict[str, Any]: # the opposite. Mainly we currently consider normalized the module listing # used by `ansible-doc -t module -l 2>/dev/null` action = removeprefix(action, "ansible.builtin.") - result["action"] = dict( - __ansible_module__=action, __ansible_module_original__=action_unnormalized - ) + result["action"] = { + "__ansible_module__": action, + "__ansible_module_original__": action_unnormalized, + } if "_raw_params" in arguments: # Doing a split here is really bad as it would break jinja2 templating diff --git a/test/test_ansiblelintrule.py b/test/test_ansiblelintrule.py index 62f37a5882..4afcd596e1 100644 --- a/test/test_ansiblelintrule.py +++ b/test/test_ansiblelintrule.py @@ -17,7 +17,7 @@ def test_unjinja() -> None: assert AnsibleLintRule.unjinja(text) == output -@pytest.mark.parametrize("rule_config", ({}, dict(foo=True, bar=1))) +@pytest.mark.parametrize("rule_config", ({}, {"foo": True, "bar": 1})) def test_rule_config(rule_config: dict[str, Any], monkeypatch: MonkeyPatch) -> None: """Check that a rule config is inherited from options.""" rule_id = "rule-0" diff --git a/test/test_matcherrror.py b/test/test_matcherrror.py index 3dfec6d32c..d3e893e28c 100644 --- a/test/test_matcherrror.py +++ b/test/test_matcherrror.py @@ -67,7 +67,7 @@ def test_matcherror_invalid() -> None: r"^MatchError\(\) missing a required argument: one of 'message' or 'rule'$" ) with pytest.raises(TypeError, match=expected_err): - MatchError() + raise MatchError() @pytest.mark.parametrize( diff --git a/test/test_skiputils.py b/test/test_skiputils.py index fc9151b2c6..e08bd470ef 100644 --- a/test/test_skiputils.py +++ b/test/test_skiputils.py @@ -189,31 +189,31 @@ def test_append_skipped_rules( ("task", "expected"), ( pytest.param( - dict( - name="ensure apache is at the latest version", - yum={"name": "httpd", "state": "latest"}, - ), + { + "name": "ensure apache is at the latest version", + "yum": {"name": "httpd", "state": "latest"}, + }, False, ), pytest.param( - dict( - name="Attempt and graceful roll back", - block=[ + { + "name": "Attempt and graceful roll back", + "block": [ {"name": "Force a failure", "ansible.builtin.command": "/bin/false"} ], - rescue=[ + "rescue": [ { "name": "Force a failure in middle of recovery!", "ansible.builtin.command": "/bin/false", } ], - always=[ + "always": [ { "name": "Always do this", "ansible.builtin.debug": {"msg": "This always executes"}, } ], - ), + }, True, ), ), diff --git a/test/test_utils.py b/test/test_utils.py index 5099a420a1..1b8f9effa2 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -83,8 +83,8 @@ def test_tokenize( ("reference_form", "alternate_forms"), ( pytest.param( - dict(name="hello", action="command chdir=abc echo hello world"), - (dict(name="hello", command="chdir=abc echo hello world"),), + {"name": "hello", "action": "command chdir=abc echo hello world"}, + ({"name": "hello", "command": "chdir=abc echo hello world"},), id="simple_command", ), pytest.param( @@ -113,12 +113,13 @@ def test_normalize( def test_normalize_complex_command() -> None: """Test that tasks specified differently are normalized same way.""" - task1 = dict( - name="hello", action={"module": "pip", "name": "df", "editable": "false"} - ) - task2 = dict(name="hello", pip={"name": "df", "editable": "false"}) - task3 = dict(name="hello", pip="name=df editable=false") - task4 = dict(name="hello", action="pip name=df editable=false") + task1 = { + "name": "hello", + "action": {"module": "pip", "name": "df", "editable": "false"}, + } + task2 = {"name": "hello", "pip": {"name": "df", "editable": "false"}} + task3 = {"name": "hello", "pip": "name=df editable=false"} + task4 = {"name": "hello", "action": "pip name=df editable=false"} assert utils.normalize_task(task1, "tasks.yml") == utils.normalize_task( task2, "tasks.yml" ) @@ -134,47 +135,47 @@ def test_normalize_complex_command() -> None: ("task", "expected_form"), ( pytest.param( - dict( - name="ensure apache is at the latest version", - yum={"name": "httpd", "state": "latest"}, - ), - dict( - delegate_to=Sentinel, - name="ensure apache is at the latest version", - action={ + { + "name": "ensure apache is at the latest version", + "yum": {"name": "httpd", "state": "latest"}, + }, + { + "delegate_to": Sentinel, + "name": "ensure apache is at the latest version", + "action": { "__ansible_module__": "yum", "__ansible_module_original__": "yum", "__ansible_arguments__": [], "name": "httpd", "state": "latest", }, - ), + }, ), pytest.param( - dict( - name="Attempt and graceful roll back", - block=[ + { + "name": "Attempt and graceful roll back", + "block": [ { "name": "Install httpd and memcached", "ansible.builtin.yum": ["httpd", "memcached"], "state": "present", } ], - ), - dict( - name="Attempt and graceful roll back", - block=[ + }, + { + "name": "Attempt and graceful roll back", + "block": [ { "name": "Install httpd and memcached", "ansible.builtin.yum": ["httpd", "memcached"], "state": "present", } ], - action={ + "action": { "__ansible_module__": "block/always/rescue", "__ansible_module_original__": "block/always/rescue", }, - ), + }, ), ), ) @@ -241,7 +242,7 @@ def test_template(template: str, output: str) -> None: result = utils.template( basedir="/base/dir", value=template, - variables=dict(playbook_dir="/a/b/c"), + variables={"playbook_dir": "/a/b/c"}, fail_on_error=False, ) assert result == output @@ -249,7 +250,7 @@ def test_template(template: str, output: str) -> None: def test_task_to_str_unicode() -> None: """Ensure that extracting messages from tasks preserves Unicode.""" - task = dict(fail=dict(msg="unicode é ô à")) + task = {"fail": {"msg": "unicode é ô à"}} result = utils.task_to_str(utils.normalize_task(task, "filename.yml")) assert result == "fail msg=unicode é ô à"