Hello pythonistas! I could use some eyes and thumb...
# python
a
Hello pythonistas! I could use some eyes and thumbs from a python typing and dataclass guru on a bug/feature where Pulumi doesn't pick up annotations from the parent dataclass, only the subclass. https://github.com/pulumi/pulumi/issues/19655 An easy fix™️, right? 😗
f
I had some discussion with regards to dataclasses / pydantic for python component resource with folks who worked on this my understanding is that neither of those are supported, and even with typeddict there are edge cases (for example, py3.10+ None | <type> syntax is not supported) what I am doing in my components: I have typeddict args AND pydantic config and the first thing I do in component resource is convert args to pydantic class
Copy code
def __init__(
        self,
        name: str,
        args: VPCArgs,
        opts: ResourceOptions | None = None,
    ):
        self.config = VPCConfig.model_validate(args)
what I would like to see in the future is support of dataclasses and pydantic classes natively
a
Thanks for sharing @famous-ambulance-44173! I want to try and avoid that duplication of type declarations and have one interface, because I'm going to end up with a lot of components and a lot of different implementations. Please give the issue a 👍 if you think it will help move dataclasses along 🙂 I was thinking a fall back for me would be to generate ComponentResource code from the interface. That is guaranteed to work for any static code analysis. But I feel like that's a dark path cowboy partying Looking at the analyzer, I don't see any reason there not to support dataclasses. I guess we need to try and clarify what is supported, what should be/could be supported. And then we need to get some tests and docs down on what's supported before extending it. I expect that this is quite a big one for the python community? 🎣 Anyone else know of some prior work / thinking here?
f
to me pydantic support would be more useful than dataclasses, but I upvoted your issue. maybe @white-camera-67848 can provide additional insight as he has been working on python component resources