Are conditional type hints currently possible? #1251
Answered
by
hmc-cs-mdrissi
randolf-scholz
asked this question in
Q&A
|
Consider the case when we have a table of pairs of types (cf. pandas-dev/pandas-stubs#262)
And I have a functon that takes as input an object of the form def convert(object: list[NumpyScalar]) -> list[PandasScalar]:How can one type hint this properly without writing a million |
Answered by
hmc-cs-mdrissi
Sep 5, 2022
Replies: 1 comment
|
No overload is only way today. You need a type level map operation which has briefly appeared in typing sig and while useful would likely be a complex feature and definitely require a pep. I think numpy dtype conversion/promotion rules is best use case for this. |
0 replies
Answer selected by
randolf-scholz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No overload is only way today.
You need a type level map operation which has briefly appeared in typing sig and while useful would likely be a complex feature and definitely require a pep. I think numpy dtype conversion/promotion rules is best use case for this.