Skip to content

Commit 75e589c

Browse files
committed
isinstance -> fast_isinstance
1 parent 04cf262 commit 75e589c

40 files changed

+123
-109
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ where
106106
// See if any exception leaked out:
107107
let exitcode = match res {
108108
Ok(()) => 0,
109-
Err(err) if err.isinstance(&vm.ctx.exceptions.system_exit) => {
109+
Err(err) if err.fast_isinstance(&vm.ctx.exceptions.system_exit) => {
110110
let args = err.args();
111111
match args.as_slice() {
112112
[] => 0,
@@ -652,7 +652,7 @@ fn get_importer(path: &str, vm: &VirtualMachine) -> PyResult<Option<PyObjectRef>
652652
importer = Some(imp);
653653
break;
654654
}
655-
Err(e) if e.isinstance(&vm.ctx.exceptions.import_error) => continue,
655+
Err(e) if e.fast_isinstance(&vm.ctx.exceptions.import_error) => continue,
656656
Err(e) => return Err(e),
657657
}
658658
}

src/shell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
127127
};
128128

129129
if let Err(exc) = result {
130-
if exc.isinstance(&vm.ctx.exceptions.system_exit) {
130+
if exc.fast_isinstance(&vm.ctx.exceptions.system_exit) {
131131
repl.save_history(&repl_history_path).unwrap();
132132
return Err(exc);
133133
}

stdlib/src/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@ mod array {
14441444
}
14451445

14461446
fn check_array_type(typ: PyTypeRef, vm: &VirtualMachine) -> PyResult<PyTypeRef> {
1447-
if !typ.issubclass(PyArray::class(vm)) {
1447+
if !typ.fast_issubclass(PyArray::class(vm)) {
14481448
return Err(
14491449
vm.new_type_error(format!("{} is not a subtype of array.array", typ.name()))
14501450
);

stdlib/src/socket.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ mod _socket {
154154
type CastFrom = libc::c_longlong;
155155

156156
// should really just be to_index() but test_socket tests the error messages explicitly
157-
if obj.isinstance(&vm.ctx.types.float_type) {
157+
if obj.fast_isinstance(&vm.ctx.types.float_type) {
158158
return Err(vm.new_type_error("integer argument expected, got float".to_owned()));
159159
}
160160
let int = vm

vm/src/builtins/asyncgenerator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl PyAsyncGenWrappedValue {
147147
fn unbox(ag: &PyAsyncGen, val: PyResult<PyIterReturn>, vm: &VirtualMachine) -> PyResult {
148148
let (closed, async_done) = match &val {
149149
Ok(PyIterReturn::StopIteration(_)) => (true, true),
150-
Err(e) if e.isinstance(&vm.ctx.exceptions.generator_exit) => (true, true),
150+
Err(e) if e.fast_isinstance(&vm.ctx.exceptions.generator_exit) => (true, true),
151151
Err(_) => (false, true),
152152
_ => (false, false),
153153
};
@@ -398,8 +398,8 @@ impl PyAsyncGenAThrow {
398398
self.ag.running_async.store(false);
399399
self.state.store(AwaitableState::Closed);
400400
if self.aclose
401-
&& (exc.isinstance(&vm.ctx.exceptions.stop_async_iteration)
402-
|| exc.isinstance(&vm.ctx.exceptions.generator_exit))
401+
&& (exc.fast_isinstance(&vm.ctx.exceptions.stop_async_iteration)
402+
|| exc.fast_isinstance(&vm.ctx.exceptions.generator_exit))
403403
{
404404
vm.new_stop_iteration(None)
405405
} else {

vm/src/builtins/bytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ impl Comparable for PyBytes {
638638
) -> PyResult<PyComparisonValue> {
639639
Ok(if let Some(res) = op.identical_optimization(zelf, other) {
640640
res.into()
641-
} else if other.isinstance(&vm.ctx.types.memoryview_type)
641+
} else if other.fast_isinstance(&vm.ctx.types.memoryview_type)
642642
&& op != PyComparisonOp::Eq
643643
&& op != PyComparisonOp::Ne
644644
{

vm/src/builtins/complex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl Constructor for PyComplex {
158158
OptionalArg::Present(obj) => {
159159
if let Some(c) = obj.try_complex(vm)? {
160160
c
161-
} else if obj.class().issubclass(&vm.ctx.types.str_type) {
161+
} else if obj.class().fast_issubclass(&vm.ctx.types.str_type) {
162162
return Err(
163163
vm.new_type_error("complex() second arg can't be a string".to_owned())
164164
);

vm/src/builtins/dict.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,9 @@ impl PyObjectView<PyDict> {
558558
} else {
559559
match self.as_object().get_item(key.clone(), vm) {
560560
Ok(value) => Ok(Some(value)),
561-
Err(e) if e.isinstance(&vm.ctx.exceptions.key_error) => self.missing_opt(key, vm),
561+
Err(e) if e.fast_isinstance(&vm.ctx.exceptions.key_error) => {
562+
self.missing_opt(key, vm)
563+
}
562564
Err(e) => Err(e),
563565
}
564566
}

vm/src/builtins/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ impl PyBoundMethod {
545545
fn qualname(&self, vm: &VirtualMachine) -> PyResult {
546546
if self
547547
.function
548-
.isinstance(&vm.ctx.types.builtin_function_or_method_type)
548+
.fast_isinstance(&vm.ctx.types.builtin_function_or_method_type)
549549
{
550550
// Special case: we work with `__new__`, which is not really a method.
551551
// It is a function, so its `__qualname__` is just `__new__`.

vm/src/builtins/genericalias.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ impl Callable for PyGenericAlias {
323323
fn call(zelf: &crate::PyObjectView<Self>, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
324324
PyType::call(&zelf.origin, args, vm).map(|obj| {
325325
if let Err(exc) = obj.set_attr("__orig_class__", zelf.to_owned(), vm) {
326-
if !exc.isinstance(&vm.ctx.exceptions.attribute_error)
327-
&& !exc.isinstance(&vm.ctx.exceptions.type_error)
326+
if !exc.fast_isinstance(&vm.ctx.exceptions.attribute_error)
327+
&& !exc.fast_isinstance(&vm.ctx.exceptions.type_error)
328328
{
329329
return Err(exc);
330330
}

0 commit comments

Comments
 (0)