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

Allow arithmetic operation between gmpy2 numbers and custom objects. #214

Closed
vinklein opened this issue Mar 4, 2019 · 0 comments
Closed

Comments

@vinklein
Copy link
Contributor

vinklein commented Mar 4, 2019

Currently gmpy2's arithmetic operators support python numbers:

>>> from gmpy2 import mpz
>>> mpz(1) + 1
mpz(2)

But does not support objects with custom __mpz__, __mpq__, __mpfr__ or __mpc__ methods :

>>> class A:
...     def __mpz__(self):
...             return mpz(1)
... 
>>> a=A()
>>> mpz(1) + a
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'mpz' and 'instance'

This issue has been first seen in sage's ticket 23052.

I am currently working on a proposal for this issue.

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

No branches or pull requests

1 participant