From 737ec12fa5feffeb68bcc0494a83a223aa889e43 Mon Sep 17 00:00:00 2001 From: Joey Date: Thu, 14 Mar 2019 20:08:41 -0700 Subject: [PATCH] Rename PyValue::{required_type => class} --- vm/src/frame.rs | 2 +- vm/src/obj/objbuiltinfunc.rs | 2 +- vm/src/obj/objbytearray.rs | 2 +- vm/src/obj/objbytes.rs | 2 +- vm/src/obj/objcode.rs | 2 +- vm/src/obj/objcomplex.rs | 2 +- vm/src/obj/objdict.rs | 2 +- vm/src/obj/objenumerate.rs | 2 +- vm/src/obj/objfilter.rs | 2 +- vm/src/obj/objfloat.rs | 2 +- vm/src/obj/objfunction.rs | 4 ++-- vm/src/obj/objgenerator.rs | 2 +- vm/src/obj/objint.rs | 2 +- vm/src/obj/objlist.rs | 2 +- vm/src/obj/objmap.rs | 2 +- vm/src/obj/objmemory.rs | 2 +- vm/src/obj/objmodule.rs | 2 +- vm/src/obj/objnone.rs | 2 +- vm/src/obj/objobject.rs | 2 +- vm/src/obj/objproperty.rs | 4 ++-- vm/src/obj/objrange.rs | 2 +- vm/src/obj/objset.rs | 2 +- vm/src/obj/objslice.rs | 2 +- vm/src/obj/objstr.rs | 2 +- vm/src/obj/objtuple.rs | 2 +- vm/src/obj/objtype.rs | 2 +- vm/src/obj/objweakref.rs | 2 +- vm/src/obj/objzip.rs | 2 +- vm/src/pyobject.rs | 30 +++++++++++++++--------------- vm/src/stdlib/re.rs | 4 ++-- vm/src/stdlib/socket.rs | 2 +- wasm/lib/src/browser_module.rs | 2 +- 32 files changed, 49 insertions(+), 49 deletions(-) diff --git a/vm/src/frame.rs b/vm/src/frame.rs index 8bf23bf98..29e7b410b 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -184,7 +184,7 @@ pub struct Frame { } impl PyValue for Frame { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.frame_type() } } diff --git a/vm/src/obj/objbuiltinfunc.rs b/vm/src/obj/objbuiltinfunc.rs index 94a8bc59b..bd5e1f73d 100644 --- a/vm/src/obj/objbuiltinfunc.rs +++ b/vm/src/obj/objbuiltinfunc.rs @@ -8,7 +8,7 @@ pub struct PyBuiltinFunction { } impl PyValue for PyBuiltinFunction { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.builtin_function_or_method_type() } } diff --git a/vm/src/obj/objbytearray.rs b/vm/src/obj/objbytearray.rs index d737efaae..1d276fc29 100644 --- a/vm/src/obj/objbytearray.rs +++ b/vm/src/obj/objbytearray.rs @@ -29,7 +29,7 @@ impl PyByteArray { } impl PyValue for PyByteArray { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.bytearray_type() } } diff --git a/vm/src/obj/objbytes.rs b/vm/src/obj/objbytes.rs index c78e919bb..c71fa5ffe 100644 --- a/vm/src/obj/objbytes.rs +++ b/vm/src/obj/objbytes.rs @@ -30,7 +30,7 @@ impl Deref for PyBytes { } impl PyValue for PyBytes { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.bytes_type() } } diff --git a/vm/src/obj/objcode.rs b/vm/src/obj/objcode.rs index 36aaf4eab..fe008f904 100644 --- a/vm/src/obj/objcode.rs +++ b/vm/src/obj/objcode.rs @@ -26,7 +26,7 @@ impl fmt::Debug for PyCode { } impl PyValue for PyCode { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.code_type() } } diff --git a/vm/src/obj/objcomplex.rs b/vm/src/obj/objcomplex.rs index 75cd455f8..aed2597b7 100644 --- a/vm/src/obj/objcomplex.rs +++ b/vm/src/obj/objcomplex.rs @@ -14,7 +14,7 @@ pub struct PyComplex { } impl PyValue for PyComplex { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.complex_type() } } diff --git a/vm/src/obj/objdict.rs b/vm/src/obj/objdict.rs index 2a0bffe45..b63988231 100644 --- a/vm/src/obj/objdict.rs +++ b/vm/src/obj/objdict.rs @@ -30,7 +30,7 @@ impl fmt::Debug for PyDict { } impl PyValue for PyDict { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.dict_type() } } diff --git a/vm/src/obj/objenumerate.rs b/vm/src/obj/objenumerate.rs index 44937377f..57264f258 100644 --- a/vm/src/obj/objenumerate.rs +++ b/vm/src/obj/objenumerate.rs @@ -17,7 +17,7 @@ pub struct PyEnumerate { } impl PyValue for PyEnumerate { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.enumerate_type() } } diff --git a/vm/src/obj/objfilter.rs b/vm/src/obj/objfilter.rs index d39373739..d7ba626e5 100644 --- a/vm/src/obj/objfilter.rs +++ b/vm/src/obj/objfilter.rs @@ -13,7 +13,7 @@ pub struct PyFilter { } impl PyValue for PyFilter { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.filter_type() } } diff --git a/vm/src/obj/objfloat.rs b/vm/src/obj/objfloat.rs index ee9502a53..dc79afd69 100644 --- a/vm/src/obj/objfloat.rs +++ b/vm/src/obj/objfloat.rs @@ -16,7 +16,7 @@ pub struct PyFloat { } impl PyValue for PyFloat { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.float_type() } } diff --git a/vm/src/obj/objfunction.rs b/vm/src/obj/objfunction.rs index f0b551933..ba09ba55b 100644 --- a/vm/src/obj/objfunction.rs +++ b/vm/src/obj/objfunction.rs @@ -23,7 +23,7 @@ impl PyFunction { } impl PyValue for PyFunction { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.function_type() } } @@ -42,7 +42,7 @@ impl PyMethod { } impl PyValue for PyMethod { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.bound_method_type() } } diff --git a/vm/src/obj/objgenerator.rs b/vm/src/obj/objgenerator.rs index 8e2434c38..fcdb23441 100644 --- a/vm/src/obj/objgenerator.rs +++ b/vm/src/obj/objgenerator.rs @@ -14,7 +14,7 @@ pub struct PyGenerator { } impl PyValue for PyGenerator { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.generator_type() } } diff --git a/vm/src/obj/objint.rs b/vm/src/obj/objint.rs index 107ec7e30..68b38fbd8 100644 --- a/vm/src/obj/objint.rs +++ b/vm/src/obj/objint.rs @@ -36,7 +36,7 @@ impl IntoPyObject for BigInt { } impl PyValue for PyInt { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.int_type() } } diff --git a/vm/src/obj/objlist.rs b/vm/src/obj/objlist.rs index ff9d7c884..f483f3a3d 100644 --- a/vm/src/obj/objlist.rs +++ b/vm/src/obj/objlist.rs @@ -38,7 +38,7 @@ impl From> for PyList { } impl PyValue for PyList { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.list_type() } } diff --git a/vm/src/obj/objmap.rs b/vm/src/obj/objmap.rs index c183da0df..b35db3b7a 100644 --- a/vm/src/obj/objmap.rs +++ b/vm/src/obj/objmap.rs @@ -12,7 +12,7 @@ pub struct PyMap { } impl PyValue for PyMap { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.map_type() } } diff --git a/vm/src/obj/objmemory.rs b/vm/src/obj/objmemory.rs index 0170ee435..9ef717615 100644 --- a/vm/src/obj/objmemory.rs +++ b/vm/src/obj/objmemory.rs @@ -9,7 +9,7 @@ pub struct PyMemoryView { } impl PyValue for PyMemoryView { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.memoryview_type() } } diff --git a/vm/src/obj/objmodule.rs b/vm/src/obj/objmodule.rs index 297ee6dc0..045d385ef 100644 --- a/vm/src/obj/objmodule.rs +++ b/vm/src/obj/objmodule.rs @@ -9,7 +9,7 @@ pub struct PyModule { pub type PyModuleRef = PyRef; impl PyValue for PyModule { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.module_type() } } diff --git a/vm/src/obj/objnone.rs b/vm/src/obj/objnone.rs index 7bddd280d..7204fcfdc 100644 --- a/vm/src/obj/objnone.rs +++ b/vm/src/obj/objnone.rs @@ -8,7 +8,7 @@ pub struct PyNone; pub type PyNoneRef = PyRef; impl PyValue for PyNone { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.none().typ() } } diff --git a/vm/src/obj/objobject.rs b/vm/src/obj/objobject.rs index 02689fea0..7f9201504 100644 --- a/vm/src/obj/objobject.rs +++ b/vm/src/obj/objobject.rs @@ -12,7 +12,7 @@ use crate::vm::VirtualMachine; pub struct PyInstance; impl PyValue for PyInstance { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.object() } } diff --git a/vm/src/obj/objproperty.rs b/vm/src/obj/objproperty.rs index af081bbf9..d888b345a 100644 --- a/vm/src/obj/objproperty.rs +++ b/vm/src/obj/objproperty.rs @@ -16,7 +16,7 @@ pub struct PyReadOnlyProperty { } impl PyValue for PyReadOnlyProperty { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.readonly_property_type() } } @@ -38,7 +38,7 @@ pub struct PyProperty { } impl PyValue for PyProperty { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.property_type() } } diff --git a/vm/src/obj/objrange.rs b/vm/src/obj/objrange.rs index be8097cea..af4ed6369 100644 --- a/vm/src/obj/objrange.rs +++ b/vm/src/obj/objrange.rs @@ -24,7 +24,7 @@ pub struct PyRange { } impl PyValue for PyRange { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.range_type() } } diff --git a/vm/src/obj/objset.rs b/vm/src/obj/objset.rs index f46c6bcae..2926e1ead 100644 --- a/vm/src/obj/objset.rs +++ b/vm/src/obj/objset.rs @@ -30,7 +30,7 @@ impl fmt::Debug for PySet { } impl PyValue for PySet { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.set_type() } } diff --git a/vm/src/obj/objslice.rs b/vm/src/obj/objslice.rs index 6b5f5c169..654b3f60a 100644 --- a/vm/src/obj/objslice.rs +++ b/vm/src/obj/objslice.rs @@ -14,7 +14,7 @@ pub struct PySlice { } impl PyValue for PySlice { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.slice_type() } } diff --git a/vm/src/obj/objstr.rs b/vm/src/obj/objstr.rs index 1ce1cdc74..14da63b03 100644 --- a/vm/src/obj/objstr.rs +++ b/vm/src/obj/objstr.rs @@ -597,7 +597,7 @@ impl PyStringRef { } impl PyValue for PyString { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.str_type() } } diff --git a/vm/src/obj/objtuple.rs b/vm/src/obj/objtuple.rs index ccbfc46da..d634a55d1 100644 --- a/vm/src/obj/objtuple.rs +++ b/vm/src/obj/objtuple.rs @@ -39,7 +39,7 @@ impl From> for PyTuple { } impl PyValue for PyTuple { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.tuple_type() } } diff --git a/vm/src/obj/objtype.rs b/vm/src/obj/objtype.rs index 69c4a96ad..73297c40d 100644 --- a/vm/src/obj/objtype.rs +++ b/vm/src/obj/objtype.rs @@ -22,7 +22,7 @@ pub struct PyClass { pub type PyClassRef = PyRef; impl PyValue for PyClass { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.type_type() } } diff --git a/vm/src/obj/objweakref.rs b/vm/src/obj/objweakref.rs index d2e2d08dc..5d24f0ddd 100644 --- a/vm/src/obj/objweakref.rs +++ b/vm/src/obj/objweakref.rs @@ -23,7 +23,7 @@ impl PyWeak { } impl PyValue for PyWeak { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.weakref_type() } } diff --git a/vm/src/obj/objzip.rs b/vm/src/obj/objzip.rs index f108ef54b..ee7f016fe 100644 --- a/vm/src/obj/objzip.rs +++ b/vm/src/obj/objzip.rs @@ -11,7 +11,7 @@ pub struct PyZip { } impl PyValue for PyZip { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.zip_type() } } diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index a68edc9c8..4e5a0bc28 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -164,7 +164,7 @@ pub fn create_type(name: &str, type_type: &PyObjectRef, base: &PyObjectRef) -> P pub struct PyNotImplemented; impl PyValue for PyNotImplemented { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.not_implemented().typ() } } @@ -173,7 +173,7 @@ impl PyValue for PyNotImplemented { pub struct PyEllipsis; impl PyValue for PyEllipsis { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.ellipsis_type.clone() } } @@ -715,21 +715,21 @@ pub struct PyRef { impl PyRef { pub fn new(ctx: &PyContext, payload: T) -> Self { PyRef { - obj: PyObject::new(payload, T::required_type(ctx)), + obj: PyObject::new(payload, T::class(ctx)), _payload: PhantomData, } } pub fn new_with_type(vm: &mut VirtualMachine, payload: T, cls: PyClassRef) -> PyResult { - let required_type = T::required_type(&vm.ctx); - if objtype::issubclass(&cls.obj, &required_type) { + let class = T::class(&vm.ctx); + if objtype::issubclass(&cls.obj, &class) { Ok(PyRef { obj: PyObject::new(payload, cls.obj), _payload: PhantomData, }) } else { let subtype = vm.to_pystr(&cls.obj)?; - let basetype = vm.to_pystr(&required_type)?; + let basetype = vm.to_pystr(&class)?; Err(vm.new_type_error(format!("{} is not a subtype of {}", subtype, basetype))) } } @@ -765,13 +765,13 @@ where T: PyValue, { fn try_from_object(vm: &mut VirtualMachine, obj: PyObjectRef) -> PyResult { - if objtype::isinstance(&obj, &T::required_type(&vm.ctx)) { + if objtype::isinstance(&obj, &T::class(&vm.ctx)) { Ok(PyRef { obj, _payload: PhantomData, }) } else { - let expected_type = vm.to_pystr(&T::required_type(&vm.ctx))?; + let expected_type = vm.to_pystr(&T::class(&vm.ctx))?; let actual_type = vm.to_pystr(&obj.typ())?; Err(vm.new_type_error(format!( "Expected type {}, not {}", @@ -1408,7 +1408,7 @@ where T: PyValue + Sized, { fn into_pyobject(self, ctx: &PyContext) -> PyResult { - Ok(PyObject::new(self, T::required_type(ctx))) + Ok(PyObject::new(self, T::class(ctx))) } } @@ -1547,7 +1547,7 @@ pub struct PyIteratorValue { } impl PyValue for PyIteratorValue { - fn required_type(ctx: &PyContext) -> PyObjectRef { + fn class(ctx: &PyContext) -> PyObjectRef { ctx.iter_type() } } @@ -1574,25 +1574,25 @@ impl PyObject { } pub trait PyValue: fmt::Debug + Sized + 'static { - fn required_type(ctx: &PyContext) -> PyObjectRef; + fn class(ctx: &PyContext) -> PyObjectRef; fn into_ref(self, ctx: &PyContext) -> PyRef { PyRef { - obj: PyObject::new(self, Self::required_type(ctx)), + obj: PyObject::new(self, Self::class(ctx)), _payload: PhantomData, } } fn into_ref_with_type(self, vm: &mut VirtualMachine, cls: PyClassRef) -> PyResult> { - let required_type = Self::required_type(&vm.ctx); - if objtype::issubclass(&cls.obj, &required_type) { + let class = Self::class(&vm.ctx); + if objtype::issubclass(&cls.obj, &class) { Ok(PyRef { obj: PyObject::new(self, cls.obj), _payload: PhantomData, }) } else { let subtype = vm.to_pystr(&cls.obj)?; - let basetype = vm.to_pystr(&required_type)?; + let basetype = vm.to_pystr(&class)?; Err(vm.new_type_error(format!("{} is not a subtype of {}", subtype, basetype))) } } diff --git a/vm/src/stdlib/re.rs b/vm/src/stdlib/re.rs index 4d6c024da..b9ce043e3 100644 --- a/vm/src/stdlib/re.rs +++ b/vm/src/stdlib/re.rs @@ -17,7 +17,7 @@ use crate::pyobject::{ use crate::VirtualMachine; impl PyValue for Regex { - fn required_type(_ctx: &PyContext) -> PyObjectRef { + fn class(_ctx: &PyContext) -> PyObjectRef { // TODO unimplemented!() } @@ -111,7 +111,7 @@ struct PyMatch { } impl PyValue for PyMatch { - fn required_type(_ctx: &PyContext) -> PyObjectRef { + fn class(_ctx: &PyContext) -> PyObjectRef { // TODO unimplemented!() } diff --git a/vm/src/stdlib/socket.rs b/vm/src/stdlib/socket.rs index c473fc467..45f4530cc 100644 --- a/vm/src/stdlib/socket.rs +++ b/vm/src/stdlib/socket.rs @@ -119,7 +119,7 @@ pub struct Socket { } impl PyValue for Socket { - fn required_type(_ctx: &PyContext) -> PyObjectRef { + fn class(_ctx: &PyContext) -> PyObjectRef { // TODO unimplemented!() } diff --git a/wasm/lib/src/browser_module.rs b/wasm/lib/src/browser_module.rs index e09a63ac6..2e964607f 100644 --- a/wasm/lib/src/browser_module.rs +++ b/wasm/lib/src/browser_module.rs @@ -158,7 +158,7 @@ pub struct PyPromise { } impl PyValue for PyPromise { - fn required_type(_ctx: &PyContext) -> PyObjectRef { + fn class(_ctx: &PyContext) -> PyObjectRef { // TODO unimplemented!() }