Is it more idiomatic in Python to use the `args=` ...
# python
g
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
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
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
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!