does anybody here have any idea how long before we...
# python
r
does anybody here have any idea how long before we get rid of all of the verbosity with Python (and in fact, every other language except for TypeScript)? By verbosity, I basically mean all of the "Args" classes that you have to type out and use, like
BucketWebsiteArgs
for
s3.Bucket
(https://www.pulumi.com/registry/packages/aws/api-docs/s3/bucket/).
a
Not yet but there've been discussions about that – supporting TypedDict and Required/NotRequired annotation: https://github.com/pulumi/pulumi/issues/11732 https://github.com/pulumi/pulumi/discussions/11500 https://peps.python.org/pep-0655/ What I've done to make my code more readable is abstracting creation of resources via functions & ComponentResource classes for more complicated resources which all share a standard input. I decided to go with Pydantic for validating config objects so the resource creation functions have no
config.get()
clutter on top of the verbosity. The verbosity is still there the stack
___main___.py
entrypoints stay clean and readable. See an example: https://gist.github.com/olafurnielsen/606566cf41673b64360a4e53728a48e1
h
i think all the inner
*Args
classes can be dicts instead? I've debated doing this, weighing the inelegance against the usefulness of type-oriented tooling
a
Yeah you can pass in kwargs but it will break type checking
h
so far, i've been using named structs, ugly as they are. I'm hoping it'll improve maintainability for the next person, but the amount of error checking they provide doesn't give me hope
r
@hundreds-gpu-71155: I just tried this with a simple test... and it works? I can't believe it. Do you know if this works for all cases? (the simple test I did: instead of
website=s3.BucketWebsiteArgs( ... )
at https://www.pulumi.com/docs/clouds/aws/get-started/deploy-changes/, I simply assigned a dictionary to
website={ ... }
@adventurous-butcher-54166: is there a typo at https://gist.github.com/olafurnielsen/606566cf41673b64360a4e53728a48e1#file-__main__-py-L3, with
stack:
?
h
I believe it works for inner argument stuff, but like I said, I don't use that style
r
thank you Jamie! one more question if I may (thank you for your patience!): I've actually never heard of named structs before... and my search results aren't really yielding anything helpful for me. Would you have some sample demo code to illustrate how you do this with Pulumi? that would be so helpful. Thank you!
h
by "named structs" i just mean using the
*Args
classes. Python doesn't have a formal struct concept, but those classes are just acting as data carriers, so they're kinda structish
r
for the record, I just tried doing this with *Args classes that you have to include in a list... like
routes
in
aws.ec2.RouteTable
, and
egress
in
aws.ec2.SecurityGroup
. Arrgh.. Edit: sorry, that would be my bad. I didn't do the change correctly and kept the `=`s. I am happy to say that of what I've tried, switching to dictionaries does work!