Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .cspell.dict/rust-more.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ bindgen
bitand
bitflags
bitor
bitvec
bitxor
bstr
byteorder
Expand Down Expand Up @@ -58,6 +59,7 @@ powi
prepended
punct
replacen
retag
rmatch
rposition
rsplitn
Expand Down Expand Up @@ -89,5 +91,3 @@ widestring
winapi
winresource
winsock
bitvec
Bitvec
6 changes: 0 additions & 6 deletions Lib/test/test_dataclasses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3672,7 +3672,6 @@ class A:
self.assertEqual(obj.a, 'a')
self.assertEqual(obj.b, 'b')

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_slots_no_weakref(self):
@dataclass(slots=True)
class A:
Expand All @@ -3687,7 +3686,6 @@ class A:
with self.assertRaises(AttributeError):
a.__weakref__

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_slots_weakref(self):
@dataclass(slots=True, weakref_slot=True)
class A:
Expand Down Expand Up @@ -3748,7 +3746,6 @@ def test_weakref_slot_make_dataclass(self):
"weakref_slot is True but slots is False"):
B = make_dataclass('B', [('a', int),], weakref_slot=True)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_weakref_slot_subclass_weakref_slot(self):
@dataclass(slots=True, weakref_slot=True)
class Base:
Expand All @@ -3767,7 +3764,6 @@ class A(Base):
a_ref = weakref.ref(a)
self.assertIs(a.__weakref__, a_ref)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_weakref_slot_subclass_no_weakref_slot(self):
@dataclass(slots=True, weakref_slot=True)
class Base:
Expand All @@ -3785,7 +3781,6 @@ class A(Base):
a_ref = weakref.ref(a)
self.assertIs(a.__weakref__, a_ref)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_weakref_slot_normal_base_weakref_slot(self):
class Base:
__slots__ = ('__weakref__',)
Expand Down Expand Up @@ -3830,7 +3825,6 @@ class B[T2]:
self.assertTrue(B.__weakref__)
B()

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_dataclass_derived_generic_from_base(self):
T = typing.TypeVar('T')

Expand Down
3 changes: 0 additions & 3 deletions Lib/test/test_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,6 @@ class X(object):
with self.assertRaisesRegex(AttributeError, "'X' object has no attribute 'a'"):
X().a

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_slots_special(self):
# Testing __dict__ and __weakref__ in __slots__...
class D(object):
Expand Down Expand Up @@ -2294,7 +2293,6 @@ def __contains__(self, value):
self.assertIn(i, p10)
self.assertNotIn(10, p10)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_weakrefs(self):
# Testing weak references...
import weakref
Expand Down Expand Up @@ -3976,7 +3974,6 @@ def __init__(self, x):
o = trash(o)
del o

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_slots_multiple_inheritance(self):
# SF bug 575229, multiple inheritance w/ slots dumps core
class A(object):
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_weakref.py
Original file line number Diff line number Diff line change
Expand Up @@ -1862,7 +1862,6 @@ def test_weak_valued_delitem(self):
self.assertEqual(len(d), 1)
self.assertEqual(list(d.items()), [('something else', o2)])

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_weak_keyed_bad_delitem(self):
d = weakref.WeakKeyDictionary()
o = Object('1')
Expand Down
4 changes: 2 additions & 2 deletions crates/stdlib/src/_asyncio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub(crate) mod _asyncio {
}

#[pyclass(
flags(BASETYPE, HAS_DICT),
flags(BASETYPE, HAS_DICT, HAS_WEAKREF),
with(Constructor, Initializer, Destructor, Representable, Iterable)
)]
impl PyFuture {
Expand Down Expand Up @@ -1169,7 +1169,7 @@ pub(crate) mod _asyncio {
}

#[pyclass(
flags(BASETYPE, HAS_DICT),
flags(BASETYPE, HAS_DICT, HAS_WEAKREF),
with(Constructor, Initializer, Destructor, Representable, Iterable)
)]
impl PyTask {
Expand Down
7 changes: 5 additions & 2 deletions crates/stdlib/src/_sqlite3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ mod _sqlite3 {
}
}

#[pyclass(with(Constructor, Callable, Initializer), flags(BASETYPE))]
#[pyclass(with(Constructor, Callable, Initializer), flags(BASETYPE, HAS_WEAKREF))]
impl Connection {
fn drop_db(&self) {
self.db.lock().take();
Expand Down Expand Up @@ -1629,7 +1629,10 @@ mod _sqlite3 {
size: Option<c_int>,
}

#[pyclass(with(Constructor, Initializer, IterNext, Iterable), flags(BASETYPE))]
#[pyclass(
with(Constructor, Initializer, IterNext, Iterable),
flags(BASETYPE, HAS_WEAKREF)
)]
impl Cursor {
fn new(
connection: PyRef<Connection>,
Expand Down
2 changes: 1 addition & 1 deletion crates/stdlib/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ mod array {
}

#[pyclass(
flags(BASETYPE),
flags(BASETYPE, HAS_WEAKREF),
with(
Comparable,
AsBuffer,
Expand Down
2 changes: 1 addition & 1 deletion crates/stdlib/src/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ mod mmap {

#[pyclass(
with(Constructor, AsMapping, AsSequence, AsBuffer, Representable),
flags(BASETYPE)
flags(BASETYPE, HAS_WEAKREF)
)]
impl PyMmap {
fn as_bytes_mut(&self) -> BorrowedValueMut<'_, [u8]> {
Expand Down
2 changes: 1 addition & 1 deletion crates/stdlib/src/re.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ mod re {
#[pyfunction]
fn purge(_vm: &VirtualMachine) {}

#[pyclass]
#[pyclass(flags(HAS_WEAKREF))]
impl PyPattern {
#[pymethod(name = "match")]
fn match_(&self, text: PyStrRef) -> Option<PyMatch> {
Expand Down
5 changes: 4 additions & 1 deletion crates/vm/src/builtins/asyncgenerator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ impl PyPayload for PyAsyncGen {
}
}

#[pyclass(flags(DISALLOW_INSTANTIATION), with(PyRef, Representable, Destructor))]
#[pyclass(
flags(DISALLOW_INSTANTIATION, HAS_WEAKREF),
with(PyRef, Representable, Destructor)
)]
impl PyAsyncGen {
pub const fn as_coro(&self) -> &Coro {
&self.inner
Expand Down
6 changes: 4 additions & 2 deletions crates/vm/src/builtins/builtin_func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub struct PyNativeFunction {
pub(crate) value: &'static PyMethodDef,
pub(crate) zelf: Option<PyObjectRef>,
pub(crate) module: Option<&'static PyStrInterned>, // None for bound method
/// Prevent HeapMethodDef from being freed while this function references it
pub(crate) _method_def_owner: Option<PyObjectRef>,
}

impl PyPayload for PyNativeFunction {
Expand Down Expand Up @@ -126,7 +128,7 @@ impl Representable for PyNativeFunction {

#[pyclass(
with(Callable, Comparable, Representable),
flags(HAS_DICT, DISALLOW_INSTANTIATION)
flags(HAS_DICT, HAS_WEAKREF, DISALLOW_INSTANTIATION)
)]
impl PyNativeFunction {
#[pygetset]
Expand Down Expand Up @@ -210,7 +212,7 @@ pub struct PyNativeMethod {
// All Python-visible behavior (getters, slots) is registered by PyNativeFunction::extend_class.
// PyNativeMethod only extends the Rust-side struct with the defining class reference.
// The func field at offset 0 (#[repr(C)]) allows NativeFunctionOrMethod to read it safely.
#[pyclass(flags(HAS_DICT, DISALLOW_INSTANTIATION))]
#[pyclass(flags(HAS_DICT, HAS_WEAKREF, DISALLOW_INSTANTIATION))]
impl PyNativeMethod {}

impl fmt::Debug for PyNativeMethod {
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/builtins/classmethod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl PyClassMethod {

#[pyclass(
with(GetDescriptor, Constructor, Initializer, Representable),
flags(BASETYPE, HAS_DICT)
flags(BASETYPE, HAS_DICT, HAS_WEAKREF)
)]
impl PyClassMethod {
#[pygetset]
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/builtins/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ impl Constructor for PyCode {
}
}

#[pyclass(with(Representable, Constructor))]
#[pyclass(with(Representable, Constructor), flags(HAS_WEAKREF))]
impl PyCode {
#[pygetset]
const fn co_posonlyargcount(&self) -> usize {
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/builtins/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl PyPayload for PyCoroutine {
}

#[pyclass(
flags(DISALLOW_INSTANTIATION),
flags(DISALLOW_INSTANTIATION, HAS_WEAKREF),
with(Py, IterNext, Representable, Destructor)
)]
impl PyCoroutine {
Expand Down
6 changes: 4 additions & 2 deletions crates/vm/src/builtins/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub struct PyMethodDescriptor {
pub method: &'static PyMethodDef,
// vectorcall: vector_call_func,
pub objclass: &'static Py<PyType>, // TODO: move to tp_members
/// Prevent HeapMethodDef from being freed while this descriptor references it
pub(crate) _method_def_owner: Option<PyObjectRef>,
}

impl PyMethodDescriptor {
Expand All @@ -49,6 +51,7 @@ impl PyMethodDescriptor {
},
method,
objclass: typ,
_method_def_owner: None,
}
}
}
Expand Down Expand Up @@ -88,13 +91,12 @@ impl GetDescriptor for PyMethodDescriptor {
} else if descr.method.flags.contains(PyMethodFlags::CLASS) {
obj.class().to_owned().into()
} else {
unimplemented!()
obj
}
}
None if descr.method.flags.contains(PyMethodFlags::CLASS) => cls.unwrap(),
None => return Ok(zelf),
};
// Ok(descr.method.build_bound_method(&vm.ctx, bound, class).into())
Ok(descr.bind(bound, &vm.ctx).into())
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/vm/src/builtins/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ impl PyPayload for PyFunction {

#[pyclass(
with(GetDescriptor, Callable, Representable, Constructor),
flags(HAS_DICT, METHOD_DESCRIPTOR)
flags(HAS_DICT, HAS_WEAKREF, METHOD_DESCRIPTOR)
)]
impl PyFunction {
#[pygetset]
Expand Down Expand Up @@ -1170,7 +1170,7 @@ impl PyBoundMethod {

#[pyclass(
with(Callable, Comparable, GetAttr, Constructor, Representable),
flags(IMMUTABLETYPE)
flags(IMMUTABLETYPE, HAS_WEAKREF)
)]
impl PyBoundMethod {
#[pymethod]
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/builtins/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl PyPayload for PyGenerator {
}

#[pyclass(
flags(DISALLOW_INSTANTIATION),
flags(DISALLOW_INSTANTIATION, HAS_WEAKREF),
with(Py, IterNext, Iterable, Representable, Destructor)
)]
impl PyGenerator {
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/builtins/genericalias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Constructor for PyGenericAlias {
Iterable,
Representable
),
flags(BASETYPE)
flags(BASETYPE, HAS_WEAKREF)
)]
impl PyGenericAlias {
pub fn new(
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/builtins/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ impl Py<PyMemoryView> {
Iterable,
Representable
),
flags(SEQUENCE)
flags(SEQUENCE, HAS_WEAKREF)
)]
impl PyMemoryView {
#[pyclassmethod]
Expand Down
5 changes: 4 additions & 1 deletion crates/vm/src/builtins/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ impl Py<PyModule> {
}
}

#[pyclass(with(GetAttr, Initializer, Representable), flags(BASETYPE, HAS_DICT))]
#[pyclass(
with(GetAttr, Initializer, Representable),
flags(BASETYPE, HAS_DICT, HAS_WEAKREF)
)]
impl PyModule {
#[pyslot]
fn slot_new(cls: PyTypeRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult {
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/builtins/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl PyPayload for PyNamespace {
impl DefaultConstructor for PyNamespace {}

#[pyclass(
flags(BASETYPE, HAS_DICT),
flags(BASETYPE, HAS_DICT, HAS_WEAKREF),
with(Constructor, Initializer, Comparable, Representable)
)]
impl PyNamespace {
Expand Down
4 changes: 4 additions & 0 deletions crates/vm/src/builtins/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ impl PyBaseObject {
if both_mutable || both_module {
let has_dict =
|typ: &Py<PyType>| typ.slots.flags.has_feature(PyTypeFlags::HAS_DICT);
let has_weakref =
|typ: &Py<PyType>| typ.slots.flags.has_feature(PyTypeFlags::HAS_WEAKREF);
// Compare slots tuples
let slots_equal = match (
current_cls
Expand All @@ -484,6 +486,8 @@ impl PyBaseObject {
if current_cls.slots.basicsize != cls.slots.basicsize
|| !slots_equal
|| has_dict(current_cls) != has_dict(&cls)
|| has_weakref(current_cls) != has_weakref(&cls)
|| current_cls.slots.member_count != cls.slots.member_count
{
return Err(vm.new_type_error(format!(
"__class__ assignment: '{}' object layout differs from '{}'",
Expand Down
5 changes: 4 additions & 1 deletion crates/vm/src/builtins/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ impl GetDescriptor for PyProperty {
}
}

#[pyclass(with(Constructor, Initializer, GetDescriptor), flags(BASETYPE))]
#[pyclass(
with(Constructor, Initializer, GetDescriptor),
flags(BASETYPE, HAS_WEAKREF)
)]
impl PyProperty {
// Helper method to get property name
// Returns the name if available, None if not found, or propagates errors
Expand Down
4 changes: 2 additions & 2 deletions crates/vm/src/builtins/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ fn reduce_set(
AsNumber,
Representable
),
flags(BASETYPE, _MATCH_SELF)
flags(BASETYPE, _MATCH_SELF, HAS_WEAKREF)
)]
impl PySet {
fn __len__(&self) -> usize {
Expand Down Expand Up @@ -996,7 +996,7 @@ impl Constructor for PyFrozenSet {
}

#[pyclass(
flags(BASETYPE, _MATCH_SELF),
flags(BASETYPE, _MATCH_SELF, HAS_WEAKREF),
with(
Constructor,
AsSequence,
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/builtins/staticmethod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Initializer for PyStaticMethod {

#[pyclass(
with(Callable, GetDescriptor, Constructor, Initializer, Representable),
flags(BASETYPE, HAS_DICT)
flags(BASETYPE, HAS_DICT, HAS_WEAKREF)
)]
impl PyStaticMethod {
#[pygetset]
Expand Down
Loading
Loading