Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add PyInt constructor for all supported number types (i32, u32, i64, u64, isize, usize, f64) #4984

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Trolldemorted
Copy link

Solves a part of #2221.

I deliberately did not implement support for PyLong_FromString because I don't feel familiar enough with the codebase to do this in my first PR.

I am aware that my ToPyInt trait will not work with PyLong_FromString, because PyLong_FromString takes more parameters than just a single value. I acknowledge that changing the trait to also accommodate PyLong_FromString will be a breaking change, but one could also add a dedicated constructor for that instead of squeezing it into new.

Copy link
Contributor

@Icxolu Icxolu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! In my opinion we should not introduce a new trait for this. This basically reimplements a subset of IntoPyObject. If we want to provide a generic constructor here, I think we should reuse the existing implementations and be generic over T: IntoPyObject<Target = PyInt, Error = Infallible>. I think that would cover all the (un)signed integer conversion. It would not cover f64 but I don't think that's a huge deal, it can easily be cast in Rust first and it is probably better to have this conversion explicit anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants