Skip to content

Update to PyO3 0.16, num-bigint 0.4, num-rational 0.4 #3

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

Merged
merged 1 commit into from
Mar 29, 2022
Merged

Update to PyO3 0.16, num-bigint 0.4, num-rational 0.4 #3

merged 1 commit into from
Mar 29, 2022

Conversation

LegionMammal978
Copy link
Contributor

@LegionMammal978 LegionMammal978 commented Mar 26, 2022

Fixes #2. The updates to num-bigint and num-rational are necessary to match the versions expected by PyO3. Note that this bumps the required Python version from 3.5 to 3.7 (released 2018-06-27) and the MSRV from nightly-2020-01-21 to 1.40.0 (released 2019-12-19).

@programmerjake
Copy link
Owner

Thanks for the contribution!

This broke the python tests. PyNumberProtocol appears to have automatically implemented the __radd__-like functions in terms of the __add__-like functions, switching to just plain methods broke that.

test commands:

pip3 install .
python3 -m unittest

unittest output:

.E...E......E.E..E...
======================================================================
ERROR: test_add (tests.test_real_algebraic_number.TestRealAlgebraicNumber)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jacob/projects/algebraics/tests/test_real_algebraic_number.py", line 188, in test_add
    self.assertEqual(1 + RealAlgebraicNumber(2), 3)
TypeError: unsupported operand type(s) for +: 'int' and 'algebraics.RealAlgebraicNumber'

======================================================================
ERROR: test_div (tests.test_real_algebraic_number.TestRealAlgebraicNumber)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jacob/projects/algebraics/tests/test_real_algebraic_number.py", line 204, in test_div
    self.assertEqual(1 / RealAlgebraicNumber(2),
TypeError: unsupported operand type(s) for /: 'int' and 'algebraics.RealAlgebraicNumber'

======================================================================
ERROR: test_mul (tests.test_real_algebraic_number.TestRealAlgebraicNumber)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jacob/projects/algebraics/tests/test_real_algebraic_number.py", line 198, in test_mul
    self.assertEqual(1 * RealAlgebraicNumber(2), 2)
TypeError: unsupported operand type(s) for *: 'int' and 'algebraics.RealAlgebraicNumber'

======================================================================
ERROR: test_pow (tests.test_real_algebraic_number.TestRealAlgebraicNumber)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jacob/projects/algebraics/tests/test_real_algebraic_number.py", line 219, in test_pow
    self.assertEqual(1 ** RealAlgebraicNumber(2), 1)
TypeError: unsupported operand type(s) for ** or pow(): 'int' and 'algebraics.RealAlgebraicNumber'

======================================================================
ERROR: test_sub (tests.test_real_algebraic_number.TestRealAlgebraicNumber)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jacob/projects/algebraics/tests/test_real_algebraic_number.py", line 193, in test_sub
    self.assertEqual(1 - RealAlgebraicNumber(2), -1)
TypeError: unsupported operand type(s) for -: 'int' and 'algebraics.RealAlgebraicNumber'

----------------------------------------------------------------------
Ran 21 tests in 0.014s

FAILED (errors=5)

@LegionMammal978
Copy link
Contributor Author

Just got the __r*__ methods working with a From<&'_ PyCell<RealAlgebraicNumberPy2>> for SharedNumber impl. I cleaned up the other impls while I was at it, and renamed RealAlgebraicNumberWrapper to SharedNumber to reduce clutter since it appears over 50 times in the file. Also, the Arc::from_mut() in try_arithmetic_helper was useless, since the RealAlgebraicNumberPy2 always holds its own strong reference, so I replaced it with a standard return.

@programmerjake programmerjake merged commit b1e6ca2 into programmerjake:master Mar 29, 2022
@programmerjake
Copy link
Owner

Thank you very much!

@programmerjake
Copy link
Owner

I published v0.3.0 to PyPI and crates.io.

cc @rotu

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.

Update to work on stable Rust aka. move to recent version of pyo3
2 participants