Hi,
I’ve been looking through some modules in ansible/lib/ansible/modules (but also community.general/plugins/modules) and all modules I’ve looked at so far do prefer the dict constructor when constructing the argument_spec
for the AnsibleModule
constructor.
Here’s an example from blockinfile.py
module = AnsibleModule(
argument_spec=dict(
path=dict(type='path', required=True, aliases=['dest', 'destfile', 'name']),
state=dict(type='str', default='present', choices=['absent', 'present']),
marker=dict(type='str', default='# {mark} ANSIBLE MANAGED BLOCK'),
...
),
...
The latest documentation on developing modules also suggests this syntax.
I’ve been wondering why the dict constructor is preferred over dict literal. pylint for example has a specfic rule R1735 to discourage this (more details on the reasons can be found here: Prefer dict literal over `dict` constructor · Issue #7690 · pylint-dev/pylint · GitHub).
Does anyone have any insight or pointers?