That’s an excellent question!
I have no idea where this comes from (dict literals have been supported since at least Python 2.0: 5.2.5 Dictionary displays, so it’s not because of “Python 2.1 did not support that yet” or a similar argument - not sure whether ansible ever supported Python 1 or whether it was available there though).
One advantage of using dict()
over {}
is that option names are forced to be Python identifiers. And that you have to type less quotes and curly brackets. Depending on your keyboard layout, that can be useful (thinking of German keyboard layouts where curly brackets are harder to type than round brackets).
Besides that, it’s mostly “we always did it that way”, I guess. I got so used to the dict()
syntax that I also use it for new modules. (I wasn’t aware it’s slower than dict literals, though the performance difference shouldn’t be relevant when using it in argument specs as the time needed to run that code is absolutely tiny compared to the effort of executing the module itself, which itself is dwarfed by the time needed to copy the module to the remote machine.)
I guess it would be a good idea to update the docs. That would at least ensure that new module authors hopefully use that as a template instead of continuing to use dict()