Skip to content

Commit e30d91f

Browse files
committed
Swap naming of is{instance, subclass} <-> real_is{instance, subclass}
1 parent 52c32fa commit e30d91f

26 files changed

+164
-157
lines changed

vm/src/builtins.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ fn builtin_eval(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
198198
);
199199

200200
// Determine code object:
201-
let code_obj = if objtype::real_isinstance(source, &vm.ctx.code_type()) {
201+
let code_obj = if objtype::isinstance(source, &vm.ctx.code_type()) {
202202
source.clone()
203-
} else if objtype::real_isinstance(source, &vm.ctx.str_type()) {
203+
} else if objtype::isinstance(source, &vm.ctx.str_type()) {
204204
let mode = compile::Mode::Eval;
205205
let source = objstr::get_value(source);
206206
// TODO: fix this newline bug:
@@ -235,7 +235,7 @@ fn builtin_exec(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
235235
);
236236

237237
// Determine code object:
238-
let code_obj = if objtype::real_isinstance(source, &vm.ctx.str_type()) {
238+
let code_obj = if objtype::isinstance(source, &vm.ctx.str_type()) {
239239
let mode = compile::Mode::Exec;
240240
let source = objstr::get_value(source);
241241
// TODO: fix this newline bug:
@@ -246,7 +246,7 @@ fn builtin_exec(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
246246
vm.new_exception(syntax_error, err.to_string())
247247
},
248248
)?
249-
} else if objtype::real_isinstance(source, &vm.ctx.code_type()) {
249+
} else if objtype::isinstance(source, &vm.ctx.code_type()) {
250250
source.clone()
251251
} else {
252252
return Err(vm.new_type_error("source argument must be str or code object".to_string()));
@@ -355,7 +355,7 @@ fn builtin_isinstance(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
355355
required = [(obj, None), (typ, Some(vm.get_type()))]
356356
);
357357

358-
let isinstance = objtype::isinstance(vm, obj, typ)?;
358+
let isinstance = objtype::real_isinstance(vm, obj, typ)?;
359359
Ok(vm.new_bool(isinstance))
360360
}
361361

@@ -366,7 +366,7 @@ fn builtin_issubclass(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
366366
required = [(subclass, Some(vm.get_type())), (cls, Some(vm.get_type()))]
367367
);
368368

369-
let issubclass = objtype::issubclass(vm, subclass, cls)?;
369+
let issubclass = objtype::real_issubclass(vm, subclass, cls)?;
370370
Ok(vm.context().new_bool(issubclass))
371371
}
372372

@@ -505,7 +505,7 @@ fn builtin_next(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
505505
match vm.call_method(iterator, "__next__", vec![]) {
506506
Ok(value) => Ok(value),
507507
Err(value) => {
508-
if objtype::real_isinstance(&value, &vm.ctx.exceptions.stop_iteration) {
508+
if objtype::isinstance(&value, &vm.ctx.exceptions.stop_iteration) {
509509
match default_value {
510510
None => Err(value),
511511
Some(value) => Ok(value.clone()),
@@ -585,7 +585,7 @@ pub fn builtin_print(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
585585
.get_optional_kwarg("sep")
586586
.filter(|obj| !obj.is(&vm.get_none()));
587587
if let Some(ref obj) = sep_arg {
588-
if !objtype::real_isinstance(obj, &vm.ctx.str_type()) {
588+
if !objtype::isinstance(obj, &vm.ctx.str_type()) {
589589
return Err(vm.new_type_error(format!(
590590
"sep must be None or a string, not {}",
591591
objtype::get_type_name(&obj.typ())
@@ -599,7 +599,7 @@ pub fn builtin_print(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
599599
.get_optional_kwarg("end")
600600
.filter(|obj| !obj.is(&vm.get_none()));
601601
if let Some(ref obj) = end_arg {
602-
if !objtype::real_isinstance(obj, &vm.ctx.str_type()) {
602+
if !objtype::isinstance(obj, &vm.ctx.str_type()) {
603603
return Err(vm.new_type_error(format!(
604604
"end must be None or a string, not {}",
605605
objtype::get_type_name(&obj.typ())
@@ -822,9 +822,9 @@ pub fn builtin_build_class_(vm: &mut VirtualMachine, mut args: PyFuncArgs) -> Py
822822
let mut metaclass = args.get_kwarg("metaclass", vm.get_type());
823823

824824
for base in bases.clone() {
825-
if objtype::issubclass(vm, &base.typ(), &metaclass)? {
825+
if objtype::real_issubclass(vm, &base.typ(), &metaclass)? {
826826
metaclass = base.typ();
827-
} else if !objtype::real_issubclass(&metaclass, &base.typ()) {
827+
} else if !objtype::issubclass(&metaclass, &base.typ()) {
828828
return Err(vm.new_type_error("metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases".to_string()));
829829
}
830830
}

vm/src/exceptions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ fn exception_init(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
2323
pub fn print_exception(vm: &mut VirtualMachine, exc: &PyObjectRef) {
2424
if let Some(tb) = exc.get_attr("__traceback__") {
2525
println!("Traceback (most recent call last):");
26-
if objtype::real_isinstance(&tb, &vm.ctx.list_type()) {
26+
if objtype::isinstance(&tb, &vm.ctx.list_type()) {
2727
let mut elements = objsequence::get_elements(&tb).to_vec();
2828
elements.reverse();
2929
for element in elements.iter() {
30-
if objtype::real_isinstance(&element, &vm.ctx.tuple_type()) {
30+
if objtype::isinstance(&element, &vm.ctx.tuple_type()) {
3131
let element = objsequence::get_elements(&element);
3232
let filename = if let Ok(x) = vm.to_str(&element[0]) {
3333
objstr::get_value(&x)

vm/src/frame.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl Frame {
105105
Err(exception) => {
106106
// unwind block stack on exception and find any handlers.
107107
// Add an entry in the traceback:
108-
assert!(objtype::real_isinstance(
108+
assert!(objtype::isinstance(
109109
&exception,
110110
&vm.ctx.exceptions.base_exception_type
111111
));
@@ -514,7 +514,7 @@ impl Frame {
514514
0 | 2 | 3 => panic!("Not implemented!"),
515515
_ => panic!("Invalid parameter for RAISE_VARARGS, must be between 0 to 3"),
516516
};
517-
if objtype::real_isinstance(&exception, &vm.ctx.exceptions.base_exception_type) {
517+
if objtype::isinstance(&exception, &vm.ctx.exceptions.base_exception_type) {
518518
info!("Exception raised: {:?}", exception);
519519
Err(exception)
520520
} else {

vm/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ macro_rules! type_check {
1919
if let Some(expected_type) = $arg_type {
2020
let arg = &$args.args[$arg_count];
2121

22-
if !$crate::obj::objtype::isinstance($vm, arg, &expected_type)? {
22+
if !$crate::obj::objtype::real_isinstance($vm, arg, &expected_type)? {
2323
let arg_typ = arg.typ();
2424
let expected_type_name = $vm.to_pystr(&expected_type)?;
2525
let actual_type = $vm.to_pystr(&arg_typ)?;

vm/src/obj/objbool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The class bool is a subclass of the class int, and cannot be subclassed.";
5050
}
5151

5252
pub fn not(vm: &mut VirtualMachine, obj: &PyObjectRef) -> PyResult {
53-
if objtype::real_isinstance(obj, &vm.ctx.bool_type()) {
53+
if objtype::isinstance(obj, &vm.ctx.bool_type()) {
5454
let value = get_value(obj);
5555
Ok(vm.ctx.new_bool(!value))
5656
} else {

vm/src/obj/objbytearray.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fn bytearray_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
121121
required = [(cls, None)],
122122
optional = [(val_option, None)]
123123
);
124-
if !objtype::real_issubclass(cls, &vm.ctx.bytearray_type()) {
124+
if !objtype::issubclass(cls, &vm.ctx.bytearray_type()) {
125125
return Err(vm.new_type_error(format!("{:?} is not a subtype of bytearray", cls)));
126126
}
127127

@@ -164,7 +164,7 @@ fn bytearray_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
164164
required = [(a, Some(vm.ctx.bytearray_type())), (b, None)]
165165
);
166166

167-
let result = if objtype::real_isinstance(b, &vm.ctx.bytearray_type()) {
167+
let result = if objtype::isinstance(b, &vm.ctx.bytearray_type()) {
168168
get_value(a).to_vec() == get_value(b).to_vec()
169169
} else {
170170
false

vm/src/obj/objbytes.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn bytes_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
5252
required = [(cls, None)],
5353
optional = [(val_option, None)]
5454
);
55-
if !objtype::real_issubclass(cls, &vm.ctx.bytes_type()) {
55+
if !objtype::issubclass(cls, &vm.ctx.bytes_type()) {
5656
return Err(vm.new_type_error(format!("{:?} is not a subtype of bytes", cls)));
5757
}
5858

@@ -85,7 +85,7 @@ fn bytes_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
8585
required = [(a, Some(vm.ctx.bytes_type())), (b, None)]
8686
);
8787

88-
let result = if objtype::real_isinstance(b, &vm.ctx.bytes_type()) {
88+
let result = if objtype::isinstance(b, &vm.ctx.bytes_type()) {
8989
get_value(a).to_vec() == get_value(b).to_vec()
9090
} else {
9191
false
@@ -100,7 +100,7 @@ fn bytes_ge(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
100100
required = [(a, Some(vm.ctx.bytes_type())), (b, None)]
101101
);
102102

103-
let result = if objtype::real_isinstance(b, &vm.ctx.bytes_type()) {
103+
let result = if objtype::isinstance(b, &vm.ctx.bytes_type()) {
104104
get_value(a).to_vec() >= get_value(b).to_vec()
105105
} else {
106106
return Err(vm.new_type_error(format!("Cannot compare {} and {} using '>'", a, b)));
@@ -115,7 +115,7 @@ fn bytes_gt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
115115
required = [(a, Some(vm.ctx.bytes_type())), (b, None)]
116116
);
117117

118-
let result = if objtype::real_isinstance(b, &vm.ctx.bytes_type()) {
118+
let result = if objtype::isinstance(b, &vm.ctx.bytes_type()) {
119119
get_value(a).to_vec() > get_value(b).to_vec()
120120
} else {
121121
return Err(vm.new_type_error(format!("Cannot compare {} and {} using '>='", a, b)));
@@ -130,7 +130,7 @@ fn bytes_le(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
130130
required = [(a, Some(vm.ctx.bytes_type())), (b, None)]
131131
);
132132

133-
let result = if objtype::real_isinstance(b, &vm.ctx.bytes_type()) {
133+
let result = if objtype::isinstance(b, &vm.ctx.bytes_type()) {
134134
get_value(a).to_vec() <= get_value(b).to_vec()
135135
} else {
136136
return Err(vm.new_type_error(format!("Cannot compare {} and {} using '<'", a, b)));
@@ -145,7 +145,7 @@ fn bytes_lt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
145145
required = [(a, Some(vm.ctx.bytes_type())), (b, None)]
146146
);
147147

148-
let result = if objtype::real_isinstance(b, &vm.ctx.bytes_type()) {
148+
let result = if objtype::isinstance(b, &vm.ctx.bytes_type()) {
149149
get_value(a).to_vec() < get_value(b).to_vec()
150150
} else {
151151
return Err(vm.new_type_error(format!("Cannot compare {} and {} using '<='", a, b)));

vm/src/obj/objcomplex.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn complex_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
6060
optional = [(real, None), (imag, None)]
6161
);
6262

63-
if !objtype::real_issubclass(cls, &vm.ctx.complex_type()) {
63+
if !objtype::issubclass(cls, &vm.ctx.complex_type()) {
6464
return Err(vm.new_type_error(format!("{:?} is not a subtype of complex", cls)));
6565
}
6666

@@ -109,9 +109,9 @@ fn complex_add(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
109109
);
110110

111111
let v1 = get_value(i);
112-
if objtype::real_isinstance(i2, &vm.ctx.complex_type()) {
112+
if objtype::isinstance(i2, &vm.ctx.complex_type()) {
113113
Ok(vm.ctx.new_complex(v1 + get_value(i2)))
114-
} else if objtype::real_isinstance(i2, &vm.ctx.int_type()) {
114+
} else if objtype::isinstance(i2, &vm.ctx.int_type()) {
115115
Ok(vm.ctx.new_complex(Complex64::new(
116116
v1.re + objint::get_value(i2).to_f64().unwrap(),
117117
v1.im,
@@ -130,7 +130,7 @@ fn complex_radd(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
130130

131131
let v1 = get_value(i);
132132

133-
if objtype::real_isinstance(i2, &vm.ctx.int_type()) {
133+
if objtype::isinstance(i2, &vm.ctx.int_type()) {
134134
Ok(vm.ctx.new_complex(Complex64::new(
135135
v1.re + objint::get_value(i2).to_f64().unwrap(),
136136
v1.im,
@@ -156,14 +156,14 @@ fn complex_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
156156

157157
let z = get_value(zelf);
158158

159-
let result = if objtype::real_isinstance(other, &vm.ctx.complex_type()) {
159+
let result = if objtype::isinstance(other, &vm.ctx.complex_type()) {
160160
z == get_value(other)
161-
} else if objtype::real_isinstance(other, &vm.ctx.int_type()) {
161+
} else if objtype::isinstance(other, &vm.ctx.int_type()) {
162162
match objint::get_value(other).to_f64() {
163163
Some(f) => z.im == 0.0f64 && z.re == f,
164164
None => false,
165165
}
166-
} else if objtype::real_isinstance(other, &vm.ctx.float_type()) {
166+
} else if objtype::isinstance(other, &vm.ctx.float_type()) {
167167
z.im == 0.0 && z.re == objfloat::get_value(other)
168168
} else {
169169
return Ok(vm.ctx.not_implemented());

vm/src/obj/objdict.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ fn dict_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
142142
);
143143
let dict = vm.ctx.new_dict();
144144
if let Some(dict_obj) = dict_obj {
145-
if objtype::real_isinstance(&dict_obj, &vm.ctx.dict_type()) {
145+
if objtype::isinstance(&dict_obj, &vm.ctx.dict_type()) {
146146
for (needle, value) in get_key_value_pairs(&dict_obj) {
147147
set_item(&dict, vm, &needle, &value);
148148
}

0 commit comments

Comments
 (0)