Skip to content

Commit 737ec12

Browse files
Rename PyValue::{required_type => class}
1 parent a1e0c03 commit 737ec12

32 files changed

+49
-49
lines changed

vm/src/frame.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub struct Frame {
184184
}
185185

186186
impl PyValue for Frame {
187-
fn required_type(ctx: &PyContext) -> PyObjectRef {
187+
fn class(ctx: &PyContext) -> PyObjectRef {
188188
ctx.frame_type()
189189
}
190190
}

vm/src/obj/objbuiltinfunc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub struct PyBuiltinFunction {
88
}
99

1010
impl PyValue for PyBuiltinFunction {
11-
fn required_type(ctx: &PyContext) -> PyObjectRef {
11+
fn class(ctx: &PyContext) -> PyObjectRef {
1212
ctx.builtin_function_or_method_type()
1313
}
1414
}

vm/src/obj/objbytearray.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl PyByteArray {
2929
}
3030

3131
impl PyValue for PyByteArray {
32-
fn required_type(ctx: &PyContext) -> PyObjectRef {
32+
fn class(ctx: &PyContext) -> PyObjectRef {
3333
ctx.bytearray_type()
3434
}
3535
}

vm/src/obj/objbytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl Deref for PyBytes {
3030
}
3131

3232
impl PyValue for PyBytes {
33-
fn required_type(ctx: &PyContext) -> PyObjectRef {
33+
fn class(ctx: &PyContext) -> PyObjectRef {
3434
ctx.bytes_type()
3535
}
3636
}

vm/src/obj/objcode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl fmt::Debug for PyCode {
2626
}
2727

2828
impl PyValue for PyCode {
29-
fn required_type(ctx: &PyContext) -> PyObjectRef {
29+
fn class(ctx: &PyContext) -> PyObjectRef {
3030
ctx.code_type()
3131
}
3232
}

vm/src/obj/objcomplex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct PyComplex {
1414
}
1515

1616
impl PyValue for PyComplex {
17-
fn required_type(ctx: &PyContext) -> PyObjectRef {
17+
fn class(ctx: &PyContext) -> PyObjectRef {
1818
ctx.complex_type()
1919
}
2020
}

vm/src/obj/objdict.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl fmt::Debug for PyDict {
3030
}
3131

3232
impl PyValue for PyDict {
33-
fn required_type(ctx: &PyContext) -> PyObjectRef {
33+
fn class(ctx: &PyContext) -> PyObjectRef {
3434
ctx.dict_type()
3535
}
3636
}

vm/src/obj/objenumerate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct PyEnumerate {
1717
}
1818

1919
impl PyValue for PyEnumerate {
20-
fn required_type(ctx: &PyContext) -> PyObjectRef {
20+
fn class(ctx: &PyContext) -> PyObjectRef {
2121
ctx.enumerate_type()
2222
}
2323
}

vm/src/obj/objfilter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct PyFilter {
1313
}
1414

1515
impl PyValue for PyFilter {
16-
fn required_type(ctx: &PyContext) -> PyObjectRef {
16+
fn class(ctx: &PyContext) -> PyObjectRef {
1717
ctx.filter_type()
1818
}
1919
}

vm/src/obj/objfloat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct PyFloat {
1616
}
1717

1818
impl PyValue for PyFloat {
19-
fn required_type(ctx: &PyContext) -> PyObjectRef {
19+
fn class(ctx: &PyContext) -> PyObjectRef {
2020
ctx.float_type()
2121
}
2222
}

vm/src/obj/objfunction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl PyFunction {
2323
}
2424

2525
impl PyValue for PyFunction {
26-
fn required_type(ctx: &PyContext) -> PyObjectRef {
26+
fn class(ctx: &PyContext) -> PyObjectRef {
2727
ctx.function_type()
2828
}
2929
}
@@ -42,7 +42,7 @@ impl PyMethod {
4242
}
4343

4444
impl PyValue for PyMethod {
45-
fn required_type(ctx: &PyContext) -> PyObjectRef {
45+
fn class(ctx: &PyContext) -> PyObjectRef {
4646
ctx.bound_method_type()
4747
}
4848
}

vm/src/obj/objgenerator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct PyGenerator {
1414
}
1515

1616
impl PyValue for PyGenerator {
17-
fn required_type(ctx: &PyContext) -> PyObjectRef {
17+
fn class(ctx: &PyContext) -> PyObjectRef {
1818
ctx.generator_type()
1919
}
2020
}

vm/src/obj/objint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl IntoPyObject for BigInt {
3636
}
3737

3838
impl PyValue for PyInt {
39-
fn required_type(ctx: &PyContext) -> PyObjectRef {
39+
fn class(ctx: &PyContext) -> PyObjectRef {
4040
ctx.int_type()
4141
}
4242
}

vm/src/obj/objlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl From<Vec<PyObjectRef>> for PyList {
3838
}
3939

4040
impl PyValue for PyList {
41-
fn required_type(ctx: &PyContext) -> PyObjectRef {
41+
fn class(ctx: &PyContext) -> PyObjectRef {
4242
ctx.list_type()
4343
}
4444
}

vm/src/obj/objmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct PyMap {
1212
}
1313

1414
impl PyValue for PyMap {
15-
fn required_type(ctx: &PyContext) -> PyObjectRef {
15+
fn class(ctx: &PyContext) -> PyObjectRef {
1616
ctx.map_type()
1717
}
1818
}

vm/src/obj/objmemory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub struct PyMemoryView {
99
}
1010

1111
impl PyValue for PyMemoryView {
12-
fn required_type(ctx: &PyContext) -> PyObjectRef {
12+
fn class(ctx: &PyContext) -> PyObjectRef {
1313
ctx.memoryview_type()
1414
}
1515
}

vm/src/obj/objmodule.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub struct PyModule {
99
pub type PyModuleRef = PyRef<PyModule>;
1010

1111
impl PyValue for PyModule {
12-
fn required_type(ctx: &PyContext) -> PyObjectRef {
12+
fn class(ctx: &PyContext) -> PyObjectRef {
1313
ctx.module_type()
1414
}
1515
}

vm/src/obj/objnone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub struct PyNone;
88
pub type PyNoneRef = PyRef<PyNone>;
99

1010
impl PyValue for PyNone {
11-
fn required_type(ctx: &PyContext) -> PyObjectRef {
11+
fn class(ctx: &PyContext) -> PyObjectRef {
1212
ctx.none().typ()
1313
}
1414
}

vm/src/obj/objobject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::vm::VirtualMachine;
1212
pub struct PyInstance;
1313

1414
impl PyValue for PyInstance {
15-
fn required_type(ctx: &PyContext) -> PyObjectRef {
15+
fn class(ctx: &PyContext) -> PyObjectRef {
1616
ctx.object()
1717
}
1818
}

vm/src/obj/objproperty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct PyReadOnlyProperty {
1616
}
1717

1818
impl PyValue for PyReadOnlyProperty {
19-
fn required_type(ctx: &PyContext) -> PyObjectRef {
19+
fn class(ctx: &PyContext) -> PyObjectRef {
2020
ctx.readonly_property_type()
2121
}
2222
}
@@ -38,7 +38,7 @@ pub struct PyProperty {
3838
}
3939

4040
impl PyValue for PyProperty {
41-
fn required_type(ctx: &PyContext) -> PyObjectRef {
41+
fn class(ctx: &PyContext) -> PyObjectRef {
4242
ctx.property_type()
4343
}
4444
}

vm/src/obj/objrange.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct PyRange {
2424
}
2525

2626
impl PyValue for PyRange {
27-
fn required_type(ctx: &PyContext) -> PyObjectRef {
27+
fn class(ctx: &PyContext) -> PyObjectRef {
2828
ctx.range_type()
2929
}
3030
}

vm/src/obj/objset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl fmt::Debug for PySet {
3030
}
3131

3232
impl PyValue for PySet {
33-
fn required_type(ctx: &PyContext) -> PyObjectRef {
33+
fn class(ctx: &PyContext) -> PyObjectRef {
3434
ctx.set_type()
3535
}
3636
}

vm/src/obj/objslice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct PySlice {
1414
}
1515

1616
impl PyValue for PySlice {
17-
fn required_type(ctx: &PyContext) -> PyObjectRef {
17+
fn class(ctx: &PyContext) -> PyObjectRef {
1818
ctx.slice_type()
1919
}
2020
}

vm/src/obj/objstr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ impl PyStringRef {
597597
}
598598

599599
impl PyValue for PyString {
600-
fn required_type(ctx: &PyContext) -> PyObjectRef {
600+
fn class(ctx: &PyContext) -> PyObjectRef {
601601
ctx.str_type()
602602
}
603603
}

vm/src/obj/objtuple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl From<Vec<PyObjectRef>> for PyTuple {
3939
}
4040

4141
impl PyValue for PyTuple {
42-
fn required_type(ctx: &PyContext) -> PyObjectRef {
42+
fn class(ctx: &PyContext) -> PyObjectRef {
4343
ctx.tuple_type()
4444
}
4545
}

vm/src/obj/objtype.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct PyClass {
2222
pub type PyClassRef = PyRef<PyClass>;
2323

2424
impl PyValue for PyClass {
25-
fn required_type(ctx: &PyContext) -> PyObjectRef {
25+
fn class(ctx: &PyContext) -> PyObjectRef {
2626
ctx.type_type()
2727
}
2828
}

vm/src/obj/objweakref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl PyWeak {
2323
}
2424

2525
impl PyValue for PyWeak {
26-
fn required_type(ctx: &PyContext) -> PyObjectRef {
26+
fn class(ctx: &PyContext) -> PyObjectRef {
2727
ctx.weakref_type()
2828
}
2929
}

vm/src/obj/objzip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct PyZip {
1111
}
1212

1313
impl PyValue for PyZip {
14-
fn required_type(ctx: &PyContext) -> PyObjectRef {
14+
fn class(ctx: &PyContext) -> PyObjectRef {
1515
ctx.zip_type()
1616
}
1717
}

vm/src/pyobject.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub fn create_type(name: &str, type_type: &PyObjectRef, base: &PyObjectRef) -> P
164164
pub struct PyNotImplemented;
165165

166166
impl PyValue for PyNotImplemented {
167-
fn required_type(ctx: &PyContext) -> PyObjectRef {
167+
fn class(ctx: &PyContext) -> PyObjectRef {
168168
ctx.not_implemented().typ()
169169
}
170170
}
@@ -173,7 +173,7 @@ impl PyValue for PyNotImplemented {
173173
pub struct PyEllipsis;
174174

175175
impl PyValue for PyEllipsis {
176-
fn required_type(ctx: &PyContext) -> PyObjectRef {
176+
fn class(ctx: &PyContext) -> PyObjectRef {
177177
ctx.ellipsis_type.clone()
178178
}
179179
}
@@ -715,21 +715,21 @@ pub struct PyRef<T> {
715715
impl<T: PyValue> PyRef<T> {
716716
pub fn new(ctx: &PyContext, payload: T) -> Self {
717717
PyRef {
718-
obj: PyObject::new(payload, T::required_type(ctx)),
718+
obj: PyObject::new(payload, T::class(ctx)),
719719
_payload: PhantomData,
720720
}
721721
}
722722

723723
pub fn new_with_type(vm: &mut VirtualMachine, payload: T, cls: PyClassRef) -> PyResult<Self> {
724-
let required_type = T::required_type(&vm.ctx);
725-
if objtype::issubclass(&cls.obj, &required_type) {
724+
let class = T::class(&vm.ctx);
725+
if objtype::issubclass(&cls.obj, &class) {
726726
Ok(PyRef {
727727
obj: PyObject::new(payload, cls.obj),
728728
_payload: PhantomData,
729729
})
730730
} else {
731731
let subtype = vm.to_pystr(&cls.obj)?;
732-
let basetype = vm.to_pystr(&required_type)?;
732+
let basetype = vm.to_pystr(&class)?;
733733
Err(vm.new_type_error(format!("{} is not a subtype of {}", subtype, basetype)))
734734
}
735735
}
@@ -765,13 +765,13 @@ where
765765
T: PyValue,
766766
{
767767
fn try_from_object(vm: &mut VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
768-
if objtype::isinstance(&obj, &T::required_type(&vm.ctx)) {
768+
if objtype::isinstance(&obj, &T::class(&vm.ctx)) {
769769
Ok(PyRef {
770770
obj,
771771
_payload: PhantomData,
772772
})
773773
} else {
774-
let expected_type = vm.to_pystr(&T::required_type(&vm.ctx))?;
774+
let expected_type = vm.to_pystr(&T::class(&vm.ctx))?;
775775
let actual_type = vm.to_pystr(&obj.typ())?;
776776
Err(vm.new_type_error(format!(
777777
"Expected type {}, not {}",
@@ -1408,7 +1408,7 @@ where
14081408
T: PyValue + Sized,
14091409
{
14101410
fn into_pyobject(self, ctx: &PyContext) -> PyResult {
1411-
Ok(PyObject::new(self, T::required_type(ctx)))
1411+
Ok(PyObject::new(self, T::class(ctx)))
14121412
}
14131413
}
14141414

@@ -1547,7 +1547,7 @@ pub struct PyIteratorValue {
15471547
}
15481548

15491549
impl PyValue for PyIteratorValue {
1550-
fn required_type(ctx: &PyContext) -> PyObjectRef {
1550+
fn class(ctx: &PyContext) -> PyObjectRef {
15511551
ctx.iter_type()
15521552
}
15531553
}
@@ -1574,25 +1574,25 @@ impl PyObject {
15741574
}
15751575

15761576
pub trait PyValue: fmt::Debug + Sized + 'static {
1577-
fn required_type(ctx: &PyContext) -> PyObjectRef;
1577+
fn class(ctx: &PyContext) -> PyObjectRef;
15781578

15791579
fn into_ref(self, ctx: &PyContext) -> PyRef<Self> {
15801580
PyRef {
1581-
obj: PyObject::new(self, Self::required_type(ctx)),
1581+
obj: PyObject::new(self, Self::class(ctx)),
15821582
_payload: PhantomData,
15831583
}
15841584
}
15851585

15861586
fn into_ref_with_type(self, vm: &mut VirtualMachine, cls: PyClassRef) -> PyResult<PyRef<Self>> {
1587-
let required_type = Self::required_type(&vm.ctx);
1588-
if objtype::issubclass(&cls.obj, &required_type) {
1587+
let class = Self::class(&vm.ctx);
1588+
if objtype::issubclass(&cls.obj, &class) {
15891589
Ok(PyRef {
15901590
obj: PyObject::new(self, cls.obj),
15911591
_payload: PhantomData,
15921592
})
15931593
} else {
15941594
let subtype = vm.to_pystr(&cls.obj)?;
1595-
let basetype = vm.to_pystr(&required_type)?;
1595+
let basetype = vm.to_pystr(&class)?;
15961596
Err(vm.new_type_error(format!("{} is not a subtype of {}", subtype, basetype)))
15971597
}
15981598
}

vm/src/stdlib/re.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::pyobject::{
1717
use crate::VirtualMachine;
1818

1919
impl PyValue for Regex {
20-
fn required_type(_ctx: &PyContext) -> PyObjectRef {
20+
fn class(_ctx: &PyContext) -> PyObjectRef {
2121
// TODO
2222
unimplemented!()
2323
}
@@ -111,7 +111,7 @@ struct PyMatch {
111111
}
112112

113113
impl PyValue for PyMatch {
114-
fn required_type(_ctx: &PyContext) -> PyObjectRef {
114+
fn class(_ctx: &PyContext) -> PyObjectRef {
115115
// TODO
116116
unimplemented!()
117117
}

0 commit comments

Comments
 (0)