Introspection: use SupportsIndex and SupportsFloat for int and float input - #6396
Introspection: use SupportsIndex and SupportsFloat for int and float input#6396jorenham wants to merge 1 commit into
SupportsIndex and SupportsFloat for int and float input#6396Conversation
|
Out of curiosity why use |
Because if you pass an object with only |
|
Ok so I guess pyo3 relies on index rather than int for conversion. I am a bit surprised but an annotation change is not the right place to change this behavior. |
|
(caution: not a PyO3 maintainer) I think this PR is correct and also does correctly reflect what PyO3 is doing internally for integer conversions, as it's using this macro AFAIS. I think the reason why reliance on
EDIT: Just to show this: >>> 1.2.__int__()
1It makes sense I guess that PyO3 chose not to accept classes purely implementing |
This widens the generated input annotations for
inttotyping.SupportsIndexand forfloattotyping.SupportsFloat | typing.SupportsIndex. This way, numpy scalars likenp.int_are no longer falsely rejected by type-checkers, even though it's supported at runtime.