diff --git a/vm/src/builtins/union.rs b/vm/src/builtins/union.rs index d43fbc10b..461c1af37 100644 --- a/vm/src/builtins/union.rs +++ b/vm/src/builtins/union.rs @@ -90,15 +90,33 @@ impl PyUnion { } #[pymethod(magic)] - fn instancecheck(_zelf: PyRef, _obj: PyObjectRef, vm: &VirtualMachine) -> PyResult { - Err(vm - .new_type_error("isinstance() argument 2 cannot be a parameterized generic".to_owned())) + fn instancecheck(zelf: PyRef, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult { + if zelf + .args + .iter() + .any(|x| x.class().is(vm.ctx.types.generic_alias_type)) + { + Err(vm.new_type_error( + "isinstance() argument 2 cannot be a parameterized generic".to_owned(), + )) + } else { + obj.is_instance(zelf.args().as_object(), vm) + } } #[pymethod(magic)] - fn subclasscheck(_zelf: PyRef, _obj: PyObjectRef, vm: &VirtualMachine) -> PyResult { - Err(vm - .new_type_error("issubclass() argument 2 cannot be a parameterized generic".to_owned())) + fn subclasscheck(zelf: PyRef, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult { + if zelf + .args + .iter() + .any(|x| x.class().is(vm.ctx.types.generic_alias_type)) + { + Err(vm.new_type_error( + "issubclass() argument 2 cannot be a parameterized generic".to_owned(), + )) + } else { + obj.is_subclass(zelf.args().as_object(), vm) + } } #[pymethod(name = "__ror__")] diff --git a/vm/src/protocol/object.rs b/vm/src/protocol/object.rs index 79e252c4e..ca7aa1455 100644 --- a/vm/src/protocol/object.rs +++ b/vm/src/protocol/object.rs @@ -398,7 +398,7 @@ impl PyObject { }) .and(self.check_cls(cls, vm, || { format!( - "issubclass() arg 2 must be a class or tuple of classes, not {}", + "issubclass() arg 2 must be a class, a tuple of classes, or a union, not {}", cls.class() ) }))