Skip to content

Commit ec0a232

Browse files
committed
Use Unconstructible trait for internal types
1 parent b2d6594 commit ec0a232

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

stdlib/src/sqlite.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ mod _sqlite {
7171
sliceable::{SaturatedSliceIter, SliceableSequenceOp},
7272
types::{
7373
AsMapping, AsSequence, Callable, Comparable, Constructor, Hashable, IterNext, Iterable,
74-
PyComparisonOp, SelfIter,
74+
PyComparisonOp, SelfIter, Unconstructible,
7575
},
7676
utils::ToCString,
7777
};
@@ -2044,13 +2044,7 @@ mod _sqlite {
20442044
inner: PyMutex<Option<BlobInner>>,
20452045
}
20462046

2047-
impl Constructor for Blob {
2048-
type Args = FuncArgs;
2049-
2050-
fn py_new(_cls: PyTypeRef, _args: Self::Args, vm: &VirtualMachine) -> PyResult {
2051-
Err(vm.new_type_error("cannot create 'sqlite3.Blob' instances"))
2052-
}
2053-
}
2047+
impl Unconstructible for Blob {}
20542048

20552049
#[derive(Debug)]
20562050
struct BlobInner {
@@ -2064,7 +2058,7 @@ mod _sqlite {
20642058
}
20652059
}
20662060

2067-
#[pyclass(with(AsMapping, Constructor))]
2061+
#[pyclass(with(AsMapping, Unconstructible))]
20682062
impl Blob {
20692063
#[pymethod]
20702064
fn close(&self) {
@@ -2381,15 +2375,9 @@ mod _sqlite {
23812375
}
23822376
}
23832377

2384-
impl Constructor for Statement {
2385-
type Args = FuncArgs;
2386-
2387-
fn py_new(_cls: PyTypeRef, _args: Self::Args, vm: &VirtualMachine) -> PyResult {
2388-
Err(vm.new_type_error("cannot create 'sqlite3.Statement' instances"))
2389-
}
2390-
}
2378+
impl Unconstructible for Statement {}
23912379

2392-
#[pyclass(with(Constructor))]
2380+
#[pyclass(with(Unconstructible))]
23932381
impl Statement {
23942382
fn new(
23952383
connection: &Connection,

vm/src/types/slot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ pub trait DefaultConstructor: PyPayload + Default {
802802
pub trait Unconstructible: PyPayload {
803803
#[pyslot]
804804
fn slot_new(cls: PyTypeRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult {
805-
Err(vm.new_type_error(format!("cannot create {} instances", cls.slot_name())))
805+
Err(vm.new_type_error(format!("cannot create '{}' instances", cls.slot_name())))
806806
}
807807
}
808808

0 commit comments

Comments
 (0)