GeezerVison is showing github.com — Deprecate ::new_ref (#6046) · RustPython/RustPython@f402dee
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: vm/src/builtins/bytearray.rs +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -73,8 +73,9 @@ pub(crate) fn init(context: &Context) { | 73 | 73 | } | 74 | 74 |
| 75 | 75 | impl PyByteArray { | | 76 | + #[deprecated(note = "use PyByteArray::from(...).into_ref() instead")] | 76 | 77 | pub fn new_ref(data: Vec<u8>, ctx: &Context) -> PyRef<Self> { | 77 | | - PyRef::new_ref(Self::from(data), ctx.types.bytearray_type.to_owned(), None) | | 78 | + Self::from(data).into_ref(ctx) | 78 | 79 | } | 79 | 80 |
| 80 | 81 | const fn from_inner(inner: PyBytesInner) -> Self { | |
Collapse file Copy file name to clipboardExpand all lines: vm/src/builtins/bytes.rs +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -99,8 +99,9 @@ impl Constructor for PyBytes { | 99 | 99 | } | 100 | 100 |
| 101 | 101 | impl PyBytes { | | 102 | + #[deprecated(note = "use PyBytes::from(...).into_ref() instead")] | 102 | 103 | pub fn new_ref(data: Vec<u8>, ctx: &Context) -> PyRef<Self> { | 103 | | - PyRef::new_ref(Self::from(data), ctx.types.bytes_type.to_owned(), None) | | 104 | + Self::from(data).into_ref(ctx) | 104 | 105 | } | 105 | 106 |
| 106 | 107 | fn _getitem(&self, needle: &PyObject, vm: &VirtualMachine) -> PyResult { | |
Collapse file Copy file name to clipboardExpand all lines: vm/src/builtins/classmethod.rs +2-7Lines changed: 2 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -111,14 +111,9 @@ impl Initializer for PyClassMethod { | 111 | 111 | } | 112 | 112 |
| 113 | 113 | impl PyClassMethod { | | 114 | + #[deprecated(note = "use PyClassMethod::from(...).into_ref() instead")] | 114 | 115 | pub fn new_ref(callable: PyObjectRef, ctx: &Context) -> PyRef<Self> { | 115 | | - PyRef::new_ref( | 116 | | - Self { | 117 | | - callable: PyMutex::new(callable), | 118 | | - }, | 119 | | - ctx.types.classmethod_type.to_owned(), | 120 | | - None, | 121 | | - ) | | 116 | + Self::from(callable).into_ref(ctx) | 122 | 117 | } | 123 | 118 | } | 124 | 119 |
| |
Collapse file Copy file name to clipboardExpand all lines: vm/src/builtins/complex.rs +18-21Lines changed: 18 additions & 21 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,12 +29,6 @@ pub struct PyComplex { | 29 | 29 | value: Complex64, | 30 | 30 | } | 31 | 31 |
| 32 | | -impl PyComplex { | 33 | | - pub const fn to_complex64(self) -> Complex64 { | 34 | | - self.value | 35 | | - } | 36 | | -} | 37 | | - | 38 | 32 | impl PyPayload for PyComplex { | 39 | 33 | #[inline] | 40 | 34 | fn class(ctx: &Context) -> &'static Py<PyType> { | @@ -234,13 +228,30 @@ impl Constructor for PyComplex { | 234 | 228 | } | 235 | 229 |
| 236 | 230 | impl PyComplex { | | 231 | + #[deprecated(note = "use PyComplex::from(...).into_ref() instead")] | 237 | 232 | pub fn new_ref(value: Complex64, ctx: &Context) -> PyRef<Self> { | 238 | | - PyRef::new_ref(Self::from(value), ctx.types.complex_type.to_owned(), None) | | 233 | + Self::from(value).into_ref(ctx) | | 234 | + } | | 235 | + | | 236 | + pub const fn to_complex64(self) -> Complex64 { | | 237 | + self.value | 239 | 238 | } | 240 | 239 |
| 241 | 240 | pub const fn to_complex(&self) -> Complex64 { | 242 | 241 | self.value | 243 | 242 | } | | 243 | + | | 244 | + fn number_op<F, R>(a: &PyObject, b: &PyObject, op: F, vm: &VirtualMachine) -> PyResult | | 245 | + where | | 246 | + F: FnOnce(Complex64, Complex64, &VirtualMachine) -> R, | | 247 | + R: ToPyResult, | | 248 | + { | | 249 | + if let (Some(a), Some(b)) = (to_op_complex(a, vm)?, to_op_complex(b, vm)?) { | | 250 | + op(a, b, vm).to_pyresult(vm) | | 251 | + } else { | | 252 | + Ok(vm.ctx.not_implemented()) | | 253 | + } | | 254 | + } | 244 | 255 | } | 245 | 256 |
| 246 | 257 | #[pyclass( | @@ -503,20 +514,6 @@ impl Representable for PyComplex { | 503 | 514 | } | 504 | 515 | } | 505 | 516 |
| 506 | | -impl PyComplex { | 507 | | - fn number_op<F, R>(a: &PyObject, b: &PyObject, op: F, vm: &VirtualMachine) -> PyResult | 508 | | - where | 509 | | - F: FnOnce(Complex64, Complex64, &VirtualMachine) -> R, | 510 | | - R: ToPyResult, | 511 | | - { | 512 | | - if let (Some(a), Some(b)) = (to_op_complex(a, vm)?, to_op_complex(b, vm)?) { | 513 | | - op(a, b, vm).to_pyresult(vm) | 514 | | - } else { | 515 | | - Ok(vm.ctx.not_implemented()) | 516 | | - } | 517 | | - } | 518 | | -} | 519 | | - | 520 | 517 | #[derive(FromArgs)] | 521 | 518 | pub struct ComplexArgs { | 522 | 519 | #[pyarg(any, optional)] | |
Collapse file Copy file name to clipboardExpand all lines: vm/src/builtins/dict.rs +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,8 +51,9 @@ impl PyPayload for PyDict { | 51 | 51 | } | 52 | 52 |
| 53 | 53 | impl PyDict { | | 54 | + #[deprecated(note = "use PyDict::default().into_ref() instead")] | 54 | 55 | pub fn new_ref(ctx: &Context) -> PyRef<Self> { | 55 | | - PyRef::new_ref(Self::default(), ctx.types.dict_type.to_owned(), None) | | 56 | + Self::default().into_ref(ctx) | 56 | 57 | } | 57 | 58 |
| 58 | 59 | /// escape hatch to access the underlying data structure directly. prefer adding a method on | |
Collapse file Copy file name to clipboardExpand all lines: vm/src/builtins/function.rs +2-5Lines changed: 2 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -773,12 +773,9 @@ impl PyBoundMethod { | 773 | 773 | Self { object, function } | 774 | 774 | } | 775 | 775 |
| | 776 | + #[deprecated(note = "Use `Self::new(object, function).into_ref(ctx)` instead")] | 776 | 777 | pub fn new_ref(object: PyObjectRef, function: PyObjectRef, ctx: &Context) -> PyRef<Self> { | 777 | | - PyRef::new_ref( | 778 | | - Self::new(object, function), | 779 | | - ctx.types.bound_method_type.to_owned(), | 780 | | - None, | 781 | | - ) | | 778 | + Self::new(object, function).into_ref(ctx) | 782 | 779 | } | 783 | 780 | } | 784 | 781 |
| |
Collapse file Copy file name to clipboardExpand all lines: vm/src/builtins/list.rs +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -63,8 +63,9 @@ impl ToPyObject for Vec<PyObjectRef> { | 63 | 63 | } | 64 | 64 |
| 65 | 65 | impl PyList { | | 66 | + #[deprecated(note = "use PyList::from(...).into_ref() instead")] | 66 | 67 | pub fn new_ref(elements: Vec<PyObjectRef>, ctx: &Context) -> PyRef<Self> { | 67 | | - PyRef::new_ref(Self::from(elements), ctx.types.list_type.to_owned(), None) | | 68 | + Self::from(elements).into_ref(ctx) | 68 | 69 | } | 69 | 70 |
| 70 | 71 | pub fn borrow_vec(&self) -> PyMappedRwLockReadGuard<'_, [PyObjectRef]> { | |
Collapse file Copy file name to clipboardExpand all lines: vm/src/builtins/namespace.rs -10Lines changed: 0 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,16 +26,6 @@ impl PyPayload for PyNamespace { | 26 | 26 |
| 27 | 27 | impl DefaultConstructor for PyNamespace {} | 28 | 28 |
| 29 | | -impl PyNamespace { | 30 | | - pub fn new_ref(ctx: &Context) -> PyRef<Self> { | 31 | | - PyRef::new_ref( | 32 | | - Self {}, | 33 | | - ctx.types.namespace_type.to_owned(), | 34 | | - Some(ctx.new_dict()), | 35 | | - ) | 36 | | - } | 37 | | -} | 38 | | - | 39 | 29 | #[pyclass( | 40 | 30 | flags(BASETYPE, HAS_DICT), | 41 | 31 | with(Constructor, Initializer, Comparable, Representable) | |
Collapse file Copy file name to clipboardExpand all lines: vm/src/builtins/set.rs +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -39,10 +39,9 @@ pub struct PySet { | 39 | 39 | } | 40 | 40 |
| 41 | 41 | impl PySet { | | 42 | + #[deprecated(note = "Use `PySet::default().into_ref(ctx)` instead")] | 42 | 43 | pub fn new_ref(ctx: &Context) -> PyRef<Self> { | 43 | | - // Initialized empty, as calling __hash__ is required for adding each object to the set | 44 | | - // which requires a VM context - this is done in the set code itself. | 45 | | - PyRef::new_ref(Self::default(), ctx.types.set_type.to_owned(), None) | | 44 | + Self::default().into_ref(ctx) | 46 | 45 | } | 47 | 46 |
| 48 | 47 | pub fn elements(&self) -> Vec<PyObjectRef> { | |
Collapse file Copy file name to clipboardExpand all lines: vm/src/builtins/staticmethod.rs +7-7Lines changed: 7 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -61,14 +61,14 @@ impl Constructor for PyStaticMethod { | 61 | 61 | } | 62 | 62 |
| 63 | 63 | impl PyStaticMethod { | | 64 | + pub fn new(callable: PyObjectRef) -> Self { | | 65 | + Self { | | 66 | + callable: PyMutex::new(callable), | | 67 | + } | | 68 | + } | | 69 | + #[deprecated(note = "use PyStaticMethod::new(...).into_ref() instead")] | 64 | 70 | pub fn new_ref(callable: PyObjectRef, ctx: &Context) -> PyRef<Self> { | 65 | | - PyRef::new_ref( | 66 | | - Self { | 67 | | - callable: PyMutex::new(callable), | 68 | | - }, | 69 | | - ctx.types.staticmethod_type.to_owned(), | 70 | | - None, | 71 | | - ) | | 71 | + Self::new(callable).into_ref(ctx) | 72 | 72 | } | 73 | 73 | } | 74 | 74 |
| |
|