diff --git a/vm/src/stdlib/thread.rs b/vm/src/stdlib/thread.rs index 93ed0e3288..4af449840b 100644 --- a/vm/src/stdlib/thread.rs +++ b/vm/src/stdlib/thread.rs @@ -5,7 +5,7 @@ use crate::{ exceptions::{self, IntoPyException}, function::{ArgCallable, FuncArgs, KwArgs, OptionalArg}, py_io, - slots::{SlotGetattro, SlotSetattro}, + slots::{SlotConstructor, SlotGetattro, SlotSetattro}, utils::Either, IdProtocol, ItemProtocol, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, VirtualMachine, @@ -103,7 +103,7 @@ impl fmt::Debug for PyLock { } } -#[pyimpl] +#[pyimpl(with(SlotConstructor))] impl PyLock { #[pymethod] #[pymethod(name = "acquire_lock")] @@ -138,6 +138,13 @@ impl PyLock { } } +impl SlotConstructor for PyLock { + type Args = FuncArgs; + fn py_new(_cls: PyTypeRef, _args: Self::Args, vm: &VirtualMachine) -> PyResult { + Err(vm.new_type_error("cannot create '_thread.lock' instances".to_owned())) + } +} + pub type RawRMutex = RawReentrantMutex; #[pyclass(module = "thread", name = "RLock")] #[derive(PyValue)]