Passing a type as a variable for dynamically created fastapi endpoints #1939
Replies: 1 comment
-
You can just ignore mypy's error here using a You could also do this in a more dynamic way by directly manipulating The way it's written currently is not very type safe however, since you're not validating that the business logic function can handle the model you're passing it, so |
Beta Was this translation helpful? Give feedback.
-
Gist URL: https://gist.github.com/mypy-play/a0067f2bc095dbdb03fc9e1933cc5ad8
Playground URL: https://mypy-play.net/?mypy=latest&python=3.12&gist=a0067f2bc095dbdb03fc9e1933cc5ad8
I'm trying to dynamically create a fastapi endpoint. For endpoints with a body I need to pass a schema. In this solution the code works fine, but I don't know how to fix a mypy problem.
I've read that variables-vs-type-aliases link, but I'm not sure that I can use
TypeAlias
in my case, because I need to pass a type as a variableBeta Was this translation helpful? Give feedback.
All reactions