diff --git a/rithm/_hints.py b/rithm/_hints.py index 10a6607..f5170ef 100644 --- a/rithm/_hints.py +++ b/rithm/_hints.py @@ -1,7 +1,11 @@ from __future__ import annotations from numbers import Rational as _Rational -from typing import TYPE_CHECKING, overload as _overload +from typing import ( + SupportsIndex as _SupportsIndex, + TYPE_CHECKING, + overload as _overload, +) from typing_extensions import Any as _Any, Self as _Self, final as _final @@ -130,7 +134,7 @@ def numerator(self, /) -> _Self: ... def bit_length(self, /) -> _Self: ... - def gcd(self, other: _Self, /) -> _Self: ... + def gcd(self, other: _SupportsIndex, /) -> _Self: ... def is_power_of_two(self, /) -> bool: ... diff --git a/rithm/_rithm.py b/rithm/_rithm.py index 542061a..f90159c 100644 --- a/rithm/_rithm.py +++ b/rithm/_rithm.py @@ -4,7 +4,7 @@ from numbers import Integral, Rational from operator import mul from sys import hash_info -from typing import Any, NoReturn, overload +from typing import Any, NoReturn, SupportsIndex, overload from typing_extensions import Self, final @@ -25,8 +25,8 @@ def numerator(self, /) -> Self: def bit_length(self, /) -> Self: return Int(self._value.bit_length()) - def gcd(self, other: Self, /) -> Self: - return Int(_gcd(self._value, other._value)) + def gcd(self, other: SupportsIndex, /) -> Self: + return Int(_gcd(self._value, other)) def is_power_of_two(self, /) -> bool: return self._value > 0 and not (self._value & (self._value - 1)) diff --git a/src/python_binding/py_int.rs b/src/python_binding/py_int.rs index 49060bd..0587d02 100644 --- a/src/python_binding/py_int.rs +++ b/src/python_binding/py_int.rs @@ -129,8 +129,8 @@ impl PyInt { } #[pyo3(text_signature = "($self, other, /)")] - fn gcd(&self, other: &Self) -> PyInt { - Self((&self.0).gcd(&other.0)) + fn gcd(&self, other: &Bound<'_, PyAny>) -> PyResult { + Ok(Self((&self.0).gcd(&try_big_int_from_py_integral(other)?))) } #[pyo3(signature = (endianness, /))]