Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cspell.dict/cpython.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
argtypes
asdl
asname
attro
augassign
badcert
badsyntax
Expand Down Expand Up @@ -50,6 +51,7 @@ prec
preinitialized
pythonw
PYTHREAD_NAME
releasebuffer
SA_ONSTACK
SOABI
stackdepth
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,6 @@ class Q2:
__qualname__ = object()
__slots__ = ["__qualname__"]

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_slots_descriptor(self):
# Issue2115: slot descriptors did not correctly check
# the type of the given object
Expand Down
4 changes: 0 additions & 4 deletions Lib/test/test_inspect/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2126,8 +2126,6 @@ class DataDescriptorSub(DataDescriptorWithNoGet,
self.assertFalse(inspect.ismethoddescriptor(MethodDescriptorSub))
self.assertFalse(inspect.ismethoddescriptor(DataDescriptorSub))

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_builtin_descriptors(self):
builtin_slot_wrapper = int.__add__ # This one is mentioned in docs.
class Owner:
Expand Down Expand Up @@ -2217,8 +2215,6 @@ class DataDescriptor2:
self.assertTrue(inspect.isdatadescriptor(DataDescriptor2()),
'class with __set__ = None is a data descriptor')

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_slot(self):
class Slotted:
__slots__ = 'foo',
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_sqlite3/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,6 @@ def test_sqlite_row_hash_cmp(self):

self.assertEqual(hash(row_1), hash(row_2))

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_sqlite_row_as_sequence(self):
""" Checks if the row object can act like a sequence """
self.con.row_factory = sqlite.Row
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_unittest/testmock/testhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,6 @@ def f(a, self): pass
a.f.assert_called_with(self=10)


# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_autospec_data_descriptor(self):
class Descriptor(object):
def __init__(self, value):
Expand Down
14 changes: 5 additions & 9 deletions crates/vm/src/builtins/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ impl PyBool {
.and_then(|format_spec| format_spec.format_bool(new_bool))
.map_err(|err| err.into_pyexception(vm))
}
}

#[pymethod(name = "__ror__")]
#[pymethod]
fn __or__(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
impl PyBool {
pub(crate) fn __or__(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
if lhs.fast_isinstance(vm.ctx.types.bool_type)
&& rhs.fast_isinstance(vm.ctx.types.bool_type)
{
Expand All @@ -143,9 +143,7 @@ impl PyBool {
}
}

#[pymethod(name = "__rand__")]
#[pymethod]
fn __and__(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
pub(crate) fn __and__(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
if lhs.fast_isinstance(vm.ctx.types.bool_type)
&& rhs.fast_isinstance(vm.ctx.types.bool_type)
{
Expand All @@ -159,9 +157,7 @@ impl PyBool {
}
}

#[pymethod(name = "__rxor__")]
#[pymethod]
fn __xor__(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
pub(crate) fn __xor__(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
if lhs.fast_isinstance(vm.ctx.types.bool_type)
&& rhs.fast_isinstance(vm.ctx.types.bool_type)
{
Expand Down
135 changes: 7 additions & 128 deletions crates/vm/src/builtins/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ use crate::{
class::PyClassImpl,
common::format::FormatSpec,
convert::{IntoPyException, ToPyObject, ToPyResult},
function::{
FuncArgs, OptionalArg, OptionalOption,
PyArithmeticValue::{self, *},
PyComparisonValue,
},
function::{FuncArgs, OptionalArg, PyComparisonValue},
protocol::PyNumberMethods,
stdlib::warnings,
types::{AsNumber, Comparable, Constructor, Hashable, PyComparisonOp, Representable},
Expand Down Expand Up @@ -268,133 +264,11 @@ impl PyComplex {
self.value.im
}

#[pymethod]
fn __abs__(&self, vm: &VirtualMachine) -> PyResult<f64> {
let Complex64 { im, re } = self.value;
let is_finite = im.is_finite() && re.is_finite();
let abs_result = re.hypot(im);
if is_finite && abs_result.is_infinite() {
Err(vm.new_overflow_error("absolute value too large"))
} else {
Ok(abs_result)
}
}

#[inline]
fn op<F>(
&self,
other: PyObjectRef,
op: F,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<Complex64>>
where
F: Fn(Complex64, Complex64) -> PyResult<Complex64>,
{
to_op_complex(&other, vm)?.map_or_else(
|| Ok(NotImplemented),
|other| Ok(Implemented(op(self.value, other)?)),
)
}

#[pymethod(name = "__radd__")]
#[pymethod]
fn __add__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<Complex64>> {
self.op(other, |a, b| Ok(a + b), vm)
}

#[pymethod]
fn __sub__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<Complex64>> {
self.op(other, |a, b| Ok(a - b), vm)
}

#[pymethod]
fn __rsub__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<Complex64>> {
self.op(other, |a, b| Ok(b - a), vm)
}

#[pymethod]
fn conjugate(&self) -> Complex64 {
self.value.conj()
}

#[pymethod(name = "__rmul__")]
#[pymethod]
fn __mul__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<Complex64>> {
self.op(other, |a, b| Ok(a * b), vm)
}

#[pymethod]
fn __truediv__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<Complex64>> {
self.op(other, |a, b| inner_div(a, b, vm), vm)
}

#[pymethod]
fn __rtruediv__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<Complex64>> {
self.op(other, |a, b| inner_div(b, a, vm), vm)
}

#[pymethod]
const fn __pos__(&self) -> Complex64 {
self.value
}

#[pymethod]
fn __neg__(&self) -> Complex64 {
-self.value
}

#[pymethod]
fn __pow__(
&self,
other: PyObjectRef,
mod_val: OptionalOption<PyObjectRef>,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<Complex64>> {
if mod_val.flatten().is_some() {
Err(vm.new_value_error("complex modulo not allowed"))
} else {
self.op(other, |a, b| inner_pow(a, b, vm), vm)
}
}

#[pymethod]
fn __rpow__(
&self,
other: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<PyArithmeticValue<Complex64>> {
self.op(other, |a, b| inner_pow(b, a, vm), vm)
}

#[pymethod]
fn __bool__(&self) -> bool {
!Complex64::is_zero(&self.value)
}

#[pymethod]
const fn __getnewargs__(&self) -> (f64, f64) {
let Complex64 { re, im } = self.value;
Expand Down Expand Up @@ -489,7 +363,12 @@ impl AsNumber for PyComplex {
}),
absolute: Some(|number, vm| {
let value = PyComplex::number_downcast(number).value;
value.norm().to_pyresult(vm)
let result = value.norm();
// Check for overflow: hypot returns inf for finite inputs that overflow
if result.is_infinite() && value.re.is_finite() && value.im.is_finite() {
return Err(vm.new_overflow_error("absolute value too large".to_owned()));
}
result.to_pyresult(vm)
}),
boolean: Some(|number, _vm| Ok(!PyComplex::number_downcast(number).value.is_zero())),
true_divide: Some(|a, b, vm| PyComplex::number_op(a, b, inner_div, vm)),
Expand Down
Loading
Loading