Find answers from the community

Updated 3 months ago

Type

Why do I not get type safety here if I explicitly pass the output_cls?
Attachment
image.png
L
N
9 comments
I thiiink i5s because it's just typed as BaseModel, because we can't know your class ahead of time?

Maybe there's a better way to use generics here, open a to a pr!
Ahhh ok, is there no way to infer the return type based on a param that is a class? I am kind of a python newbie so it will probably be difficult to contribute
It is a valid pydantic object πŸ˜… But pythons type-checking is... hard to work with for dynamic stuff like this.
You can safely cast it if you need type hints to work later on
Why can’t the function itself cast it to the given type then πŸ˜…
Will do some research on this haha, feels like it should be easy
because python is spooky? Idk actually haha
I havent looked much deeper, I feel like the solution here might be generics. But let me know if you find anything
Add a reply
Sign up and join the conversation on Discord