Skip to content

Commit 74bfae0

Browse files
committed
DISALLOW_INSTANTIATION
1 parent 4fcce4d commit 74bfae0

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

crates/vm/src/stdlib/ctypes/field.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::builtins::{PyType, PyTypeRef};
1+
use crate::builtins::PyType;
22
use crate::function::PySetterValue;
3-
use crate::types::{Constructor, GetDescriptor, Representable};
3+
use crate::types::{GetDescriptor, Representable, Unconstructible};
44
use crate::{AsObject, Py, PyObjectRef, PyResult, VirtualMachine};
55
use num_traits::ToPrimitive;
66

@@ -83,21 +83,7 @@ impl Representable for PyCField {
8383
}
8484
}
8585

86-
#[derive(Debug, FromArgs)]
87-
pub struct PyCFieldConstructorArgs {
88-
// PyObject *name, PyObject *proto,
89-
// Py_ssize_t byte_size, Py_ssize_t byte_offset,
90-
// Py_ssize_t index, int _internal_use,
91-
// PyObject *bit_size_obj, PyObject *bit_offset_obj
92-
}
93-
94-
impl Constructor for PyCField {
95-
type Args = PyCFieldConstructorArgs;
96-
97-
fn py_new(_cls: PyTypeRef, _args: Self::Args, vm: &VirtualMachine) -> PyResult {
98-
Err(vm.new_type_error("Cannot instantiate a PyCField".to_string()))
99-
}
100-
}
86+
impl Unconstructible for PyCField {}
10187

10288
impl GetDescriptor for PyCField {
10389
fn descr_get(
@@ -186,8 +172,8 @@ impl PyCField {
186172
}
187173

188174
#[pyclass(
189-
flags(BASETYPE, IMMUTABLETYPE),
190-
with(Constructor, Representable, GetDescriptor)
175+
flags(DISALLOW_INSTANTIATION, IMMUTABLETYPE),
176+
with(Unconstructible, Representable, GetDescriptor)
191177
)]
192178
impl PyCField {
193179
#[pyslot]

crates/vm/src/types/slot.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ bitflags! {
125125
const MANAGED_DICT = 1 << 4;
126126
const SEQUENCE = 1 << 5;
127127
const MAPPING = 1 << 6;
128+
const DISALLOW_INSTANTIATION = 1 << 7;
128129
const IMMUTABLETYPE = 1 << 8;
129130
const HEAPTYPE = 1 << 9;
130131
const BASETYPE = 1 << 10;

0 commit comments

Comments
 (0)