Are conditional type hints currently possible? #1251
-
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 |
Beta Was this translation helpful? Give feedback.
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. |
Beta Was this translation helpful? Give feedback.
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.