[Question] How to validate input or output nested dict? #472
-
|
In RAGFlow project, many functions accept a nested dict as input, or return a nested dict at output. ranks["chunks"] is a list of |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
For the record, this is really / only a python typing question; this has nothing to do with beartype. A better place for something unrelated would be a Discussion. But to answer your question, you need to define a type in order to type check against it. |
Beta Was this translation helpful? Give feedback.
-
|
Ho, ho, ho. Merry QA Christmas, one and all! 🎅 Santa @leycec has answers – but nobody is gonna like them. Sadly, my answers are all basically the exact same as @JWCS's. You have multiple options here. In descending order of badness:
Personally, I favour the
|
Beta Was this translation helpful? Give feedback.
Ho, ho, ho. Merry QA Christmas, one and all! 🎅
Santa @leycec has answers – but nobody is gonna like them. Sadly, my answers are all basically the exact same as @JWCS's. You have multiple options here. In descending order of badness:
[EASY-PEASY] Just use standard
dict[...]type hints subscripted by unions over all possible values that those dictionaries can contain. This approach is easy, because (A) it's perfectly supported by the most recent release of @beartype and (B) you don't need to define any additional classes. It looks something like this: