Best practice for flag-controlled size of return tuple? #783
Replies: 1 comment 4 replies
-
It seems like this kind of API might be a bit confusing to use from the Python end, and very difficult to type-check if you ever want to use MyPy/PyRight. This aspect is not to be underestimated, since type-checkable projects are much easier to use in tools like VSCode that leverage the type annotations (you get squiggly underlines when something is wrong, and autocomplete becomes generally much more effective). If you already computed the result, then what's wrong with just returning all of them? Then the user can ignore some return values as in
It ultimately ends up being less verbose and produces a function with a consistent type signature. |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm new to writing python bindings. I'm wondering if the is the best style for dealing with flags that control which objects are returned. Generally my outputs will be Eigen matrices on the C++ side. This example is pretty representative:
Alternatively I could consider every combination of the flags in a long cascade of if statements, but I'm hope for something tidier like this. Are there any pitfalls to the above approach? Any thing to improve?
Beta Was this translation helpful? Give feedback.
All reactions