mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Fix pow() raising ValueError instead of TypeError for non-int exponent (#7725)
* Validate pow() exponent type before zero-modulus check * Add tests for pow() exponent type check
This commit is contained in:
@@ -395,6 +395,9 @@ impl PyInt {
|
||||
}
|
||||
|
||||
fn modpow(&self, other: PyObjectRef, modulus: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
if other.downcast_ref::<Self>().is_none() {
|
||||
return Ok(vm.ctx.not_implemented());
|
||||
}
|
||||
let modulus = match modulus.downcast_ref::<Self>() {
|
||||
Some(val) => val.as_bigint(),
|
||||
None => return Ok(vm.ctx.not_implemented()),
|
||||
|
||||
@@ -22,6 +22,9 @@ assert_raises(TypeError, pow, 2.0, 4, 5)
|
||||
assert pow(2, -1, 5) == 3
|
||||
assert_raises(ValueError, pow, 2, 2, 0)
|
||||
|
||||
assert_raises(TypeError, pow, 1, None, 0)
|
||||
assert_raises(TypeError, pow, True, 1.5, False)
|
||||
|
||||
|
||||
assert_almost_equal = assert_equal
|
||||
|
||||
|
||||
Reference in New Issue
Block a user