-
Notifications
You must be signed in to change notification settings - Fork 779
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 num-rational
support for Python's fractions.Fraction
type
#4148
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Overall this does look good to me.
I think we need to make one small change to not leak reference counts (but someone with a bit more CPython API experience than me should probably double check).
Thanks for review @Icxolu. I have addressed your remarks :). |
CodSpeed Performance ReportMerging #4148 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spotted one small problem, otherwise this look good to me now🚀 Could you also rebase on main please, to unblock CI.
src/conversions/num_rational.rs
Outdated
#[test] | ||
fn test_fraction_as_tuples() { | ||
Python::with_gil(|py| { | ||
let locals = PyDict::new_bound(py); | ||
let py_bound = py.run_bound( | ||
"import fractions\npy_frac = fractions.Fraction(fractions.Fraction((10,)))", | ||
None, | ||
Some(&locals), | ||
); | ||
assert!(py_bound.is_err()); | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this was a bit unclear (and part of my fault for misremembering call1
from above), but what I meant was just the test of into_py
(which you have in the prop tests below). This now just tests the behavior of fractions.Fraction
which is not that useful for us. Perhaps we can instead add special case of the test_int_roundtrip
that also runs on wasm32
.
Then this is good to go 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem! Hopefully this time is the charm :) Thanks for the review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me now! Thanks for implementing 🚀 (and for the patience with my review 😁)
Hi,
This should close #3105 by adding support for Python's
fractions.Fraction
type usingnum-rational
.