how to return importable Union Type from Function #4973
Unanswered
BenediktMaag
asked this question in
Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Let's say i have function that can either return a string or an int, i would define the function to return a Py.
The rust code might look something like this:
I want to make it known to my package users how to use the api, so I'm creating a type stub __init__.pyi:
Since the actual usecase would consider more variants i want to create a type union:
If my users want to use my function they could do:
if they have a function that forwards my type, they might want to do something like:
This will satisfy the type checker but fail at runtime because the rust plugin does not actually expose the union typedefinition.
Is this currently even possible? I had two ideas but they both are limited and dont seem to work as wanted:
This will return e.g. an MyReturnType_Int but I don't kow how to directly return the inner of the enum:
The other possibility is deriving IntoPyObject:
But this will stop me from adding MyReturnType to my module since it is not a class anymore.
Beta Was this translation helpful? Give feedback.
All reactions