https://pulumi.com logo
Title
g

gorgeous-minister-41131

03/23/2023, 10:10 PM
Is it more idiomatic in Python to use the
args=
keyword and pass in an instantiated WhateverArgs class or use each arg from that class in the constructor of the resource? I notice a lot of TypeScript examples have the second parameter be the entire object of args (class), but a lot of python examples use the named keyword arguments of args as part of the resources' constructor arguments...
r

red-match-15116

03/23/2023, 10:43 PM
I think probably more idiomatic python is to use the kwargs. The args= instantiated WhateverArgs were added on as an alternative interface in scenarios where folks wanted to pass around a bag of
Args
to multiple constructors. Kinda up to you what path you choose, but I imagine the examples were created before we added on the
WhateverArgs
way of doing things, which explains why they almost exclusively use kwargs
g

gorgeous-minister-41131

03/24/2023, 5:19 PM
Understood. The bag of Args does sound handy for being able to template and not have to pass them into constructors using
**
dictionary syntax for unpacking and maybe, mentally, keeps in line with how TypeScript is also passing in these arguments. So maybe, arguably, if you had both TS and Python code bases, using
args
might keep things consistent from a mental perspective when conjuring up resources. I'll think on whether I want to start using
args
kw or not.
So I am giving the args bags a try with
args=WhateverArgs()
and so far I like how it feels consistent with the other dialects.. maybe it's not as idomatic python but I prefer the consistency when comparing to the other language dialects.
r

red-match-15116

03/27/2023, 4:28 PM
At the end of the day the best interface to use is the one that works best for you, and that's why we have the option to do either!