diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py index fd6e6de5fc..f4ede9838b 100644 --- a/Lib/test/test_complex.py +++ b/Lib/test/test_complex.py @@ -307,8 +307,6 @@ def test_boolcontext(self): def test_conjugate(self): self.assertClose(complex(5.3, 9.8).conjugate(), 5.3-9.8j) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_constructor(self): class NS: def __init__(self, value): self.value = value diff --git a/compiler/codegen/src/compile.rs b/compiler/codegen/src/compile.rs index 217c2dc02b..e5976047a3 100644 --- a/compiler/codegen/src/compile.rs +++ b/compiler/codegen/src/compile.rs @@ -507,9 +507,8 @@ impl Compiler { SymbolScope::Cell => { cache = &mut info.cellvar_cache; NameOpType::Deref - } - // // TODO: is this right? - // SymbolScope::Unknown => NameOpType::Global, + } // TODO: is this right? + // SymbolScope::Unknown => NameOpType::Global, }; if NameUsage::Load == usage && name == "__debug__" { diff --git a/vm/src/builtins/complex.rs b/vm/src/builtins/complex.rs index 609dcb9b6c..dc8f055e23 100644 --- a/vm/src/builtins/complex.rs +++ b/vm/src/builtins/complex.rs @@ -9,6 +9,7 @@ use crate::{ }, identifier, protocol::PyNumberMethods, + stdlib::warnings, types::{AsNumber, Comparable, Constructor, Hashable, PyComparisonOp, Representable}, AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; @@ -59,14 +60,31 @@ impl PyObjectRef { } if let Some(method) = vm.get_method(self.clone(), identifier!(vm, __complex__)) { let result = method?.call((), vm)?; - // TODO: returning strict subclasses of complex in __complex__ is deprecated - return match result.payload::() { - Some(complex_obj) => Ok(Some((complex_obj.value, true))), - None => Err(vm.new_type_error(format!( - "__complex__ returned non-complex (type '{}')", - result.class().name() - ))), - }; + + let ret_class = result.class().to_owned(); + if let Some(ret) = result.downcast_ref::() { + warnings::warn( + vm.ctx.exceptions.deprecation_warning, + format!( + "__complex__ returned non-complex (type {}). \ + The ability to return an instance of a strict subclass of complex \ + is deprecated, and may be removed in a future version of Python.", + ret_class + ), + 1, + vm, + )?; + + return Ok(Some((ret.value, true))); + } else { + return match result.payload::() { + Some(complex_obj) => Ok(Some((complex_obj.value, true))), + None => Err(vm.new_type_error(format!( + "__complex__ returned non-complex (type '{}')", + result.class().name() + ))), + }; + } } // `complex` does not have a `__complex__` by default, so subclasses might not either, // use the actual stored value in this case