Skip to content

Commit dc0dec0

Browse files
committed
Add HAS_WEAKREF to code, union, partial, lock, IO, mmap, sre, sqlite3, typevar types
Add HAS_WEAKREF flag to built-in types that support weakref: - PyCode, PyUnion, PyPartial, Lock, RLock - All IO base/concrete classes (_IOBase, _RawIOBase, _BufferedIOBase, _TextIOBase, BufferedReader, BufferedWriter, BufferedRandom, BufferedRWPair, TextIOWrapper, StringIO, BytesIO, FileIO, WindowsConsoleIO) - PyMmap, sre Pattern, sqlite3 Connection/Cursor - TypeVar, ParamSpec, ParamSpecArgs, ParamSpecKwargs, TypeVarTuple Remove 3 expectedFailure markers from test_descr for now-passing tests.
1 parent 64fe536 commit dc0dec0

File tree

11 files changed

+46
-31
lines changed

11 files changed

+46
-31
lines changed

Lib/test/test_descr.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,6 @@ class X(object):
13211321
with self.assertRaisesRegex(AttributeError, "'X' object has no attribute 'a'"):
13221322
X().a
13231323

1324-
@unittest.expectedFailure # TODO: RUSTPYTHON
13251324
def test_slots_special(self):
13261325
# Testing __dict__ and __weakref__ in __slots__...
13271326
class D(object):
@@ -2294,7 +2293,6 @@ def __contains__(self, value):
22942293
self.assertIn(i, p10)
22952294
self.assertNotIn(10, p10)
22962295

2297-
@unittest.expectedFailure # TODO: RUSTPYTHON
22982296
def test_weakrefs(self):
22992297
# Testing weak references...
23002298
import weakref
@@ -3976,7 +3974,6 @@ def __init__(self, x):
39763974
o = trash(o)
39773975
del o
39783976

3979-
@unittest.expectedFailure # TODO: RUSTPYTHON
39803977
def test_slots_multiple_inheritance(self):
39813978
# SF bug 575229, multiple inheritance w/ slots dumps core
39823979
class A(object):

crates/stdlib/src/_sqlite3.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ mod _sqlite3 {
976976
}
977977
}
978978

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

1632-
#[pyclass(with(Constructor, Initializer, IterNext, Iterable), flags(BASETYPE))]
1632+
#[pyclass(
1633+
with(Constructor, Initializer, IterNext, Iterable),
1634+
flags(BASETYPE, HAS_WEAKREF)
1635+
)]
16331636
impl Cursor {
16341637
fn new(
16351638
connection: PyRef<Connection>,

crates/stdlib/src/mmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ mod mmap {
851851

852852
#[pyclass(
853853
with(Constructor, AsMapping, AsSequence, AsBuffer, Representable),
854-
flags(BASETYPE)
854+
flags(BASETYPE, HAS_WEAKREF)
855855
)]
856856
impl PyMmap {
857857
fn as_bytes_mut(&self) -> BorrowedValueMut<'_, [u8]> {

crates/stdlib/src/re.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ mod re {
317317
#[pyfunction]
318318
fn purge(_vm: &VirtualMachine) {}
319319

320-
#[pyclass]
320+
#[pyclass(flags(HAS_WEAKREF))]
321321
impl PyPattern {
322322
#[pymethod(name = "match")]
323323
fn match_(&self, text: PyStrRef) -> Option<PyMatch> {

crates/vm/src/builtins/code.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ impl Constructor for PyCode {
597597
}
598598
}
599599

600-
#[pyclass(with(Representable, Constructor))]
600+
#[pyclass(with(Representable, Constructor), flags(HAS_WEAKREF))]
601601
impl PyCode {
602602
#[pygetset]
603603
const fn co_posonlyargcount(&self) -> usize {

crates/vm/src/builtins/union.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl PyUnion {
9898
}
9999

100100
#[pyclass(
101-
flags(DISALLOW_INSTANTIATION),
101+
flags(DISALLOW_INSTANTIATION, HAS_WEAKREF),
102102
with(Hashable, Comparable, AsMapping, AsNumber, Representable)
103103
)]
104104
impl PyUnion {

crates/vm/src/stdlib/functools.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ mod _functools {
140140

141141
#[pyclass(
142142
with(Constructor, Callable, GetDescriptor, Representable),
143-
flags(BASETYPE, HAS_DICT)
143+
flags(BASETYPE, HAS_DICT, HAS_WEAKREF)
144144
)]
145145
impl PyPartial {
146146
#[pygetset]

crates/vm/src/stdlib/io.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,10 @@ mod _io {
411411
#[derive(Debug, Default, PyPayload)]
412412
pub struct _IOBase;
413413

414-
#[pyclass(with(IterNext, Iterable, Destructor), flags(BASETYPE, HAS_DICT))]
414+
#[pyclass(
415+
with(IterNext, Iterable, Destructor),
416+
flags(BASETYPE, HAS_DICT, HAS_WEAKREF)
417+
)]
415418
impl _IOBase {
416419
#[pymethod]
417420
fn seek(
@@ -632,7 +635,7 @@ mod _io {
632635
#[repr(transparent)]
633636
pub(super) struct _RawIOBase(_IOBase);
634637

635-
#[pyclass(flags(BASETYPE, HAS_DICT))]
638+
#[pyclass(flags(BASETYPE, HAS_DICT, HAS_WEAKREF))]
636639
impl _RawIOBase {
637640
#[pymethod]
638641
fn read(instance: PyObjectRef, size: OptionalSize, vm: &VirtualMachine) -> PyResult {
@@ -718,7 +721,7 @@ mod _io {
718721
#[repr(transparent)]
719722
struct _BufferedIOBase(_IOBase);
720723

721-
#[pyclass(flags(BASETYPE))]
724+
#[pyclass(flags(BASETYPE, HAS_WEAKREF))]
722725
impl _BufferedIOBase {
723726
#[pymethod]
724727
fn read(zelf: PyObjectRef, _size: OptionalArg, vm: &VirtualMachine) -> PyResult {
@@ -783,7 +786,7 @@ mod _io {
783786
#[repr(transparent)]
784787
struct _TextIOBase(_IOBase);
785788

786-
#[pyclass(flags(BASETYPE))]
789+
#[pyclass(flags(BASETYPE, HAS_WEAKREF))]
787790
impl _TextIOBase {
788791
#[pygetset]
789792
fn encoding(_zelf: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
@@ -1979,7 +1982,7 @@ mod _io {
19791982

19801983
#[pyclass(
19811984
with(Constructor, BufferedMixin, BufferedReadable, Destructor),
1982-
flags(BASETYPE, HAS_DICT)
1985+
flags(BASETYPE, HAS_DICT, HAS_WEAKREF)
19831986
)]
19841987
impl BufferedReader {}
19851988

@@ -2083,7 +2086,7 @@ mod _io {
20832086

20842087
#[pyclass(
20852088
with(Constructor, BufferedMixin, BufferedWritable, Destructor),
2086-
flags(BASETYPE, HAS_DICT)
2089+
flags(BASETYPE, HAS_DICT, HAS_WEAKREF)
20872090
)]
20882091
impl BufferedWriter {}
20892092

@@ -2157,7 +2160,7 @@ mod _io {
21572160
BufferedWritable,
21582161
Destructor
21592162
),
2160-
flags(BASETYPE, HAS_DICT)
2163+
flags(BASETYPE, HAS_DICT, HAS_WEAKREF)
21612164
)]
21622165
impl BufferedRandom {}
21632166

@@ -2227,7 +2230,7 @@ mod _io {
22272230
BufferedWritable,
22282231
Destructor
22292232
),
2230-
flags(BASETYPE, HAS_DICT)
2233+
flags(BASETYPE, HAS_DICT, HAS_WEAKREF)
22312234
)]
22322235
impl BufferedRWPair {
22332236
#[pymethod]
@@ -3013,7 +3016,7 @@ mod _io {
30133016
IterNext,
30143017
Representable
30153018
),
3016-
flags(BASETYPE)
3019+
flags(BASETYPE, HAS_WEAKREF)
30173020
)]
30183021
impl TextIOWrapper {
30193022
#[pymethod]
@@ -4374,7 +4377,7 @@ mod _io {
43744377
}
43754378
}
43764379

4377-
#[pyclass(flags(BASETYPE, HAS_DICT), with(Constructor, Initializer))]
4380+
#[pyclass(flags(BASETYPE, HAS_DICT, HAS_WEAKREF), with(Constructor, Initializer))]
43784381
impl StringIO {
43794382
#[pymethod]
43804383
const fn readable(&self) -> bool {
@@ -4591,7 +4594,10 @@ mod _io {
45914594
}
45924595
}
45934596

4594-
#[pyclass(flags(BASETYPE, HAS_DICT), with(PyRef, Constructor, Initializer))]
4597+
#[pyclass(
4598+
flags(BASETYPE, HAS_DICT, HAS_WEAKREF),
4599+
with(PyRef, Constructor, Initializer)
4600+
)]
45954601
impl BytesIO {
45964602
#[pymethod]
45974603
const fn readable(&self) -> bool {
@@ -5577,7 +5583,7 @@ mod fileio {
55775583

55785584
#[pyclass(
55795585
with(Constructor, Initializer, Representable, Destructor),
5580-
flags(BASETYPE, HAS_DICT)
5586+
flags(BASETYPE, HAS_DICT, HAS_WEAKREF)
55815587
)]
55825588
impl FileIO {
55835589
fn io_error(
@@ -6333,7 +6339,7 @@ mod winconsoleio {
63336339

63346340
#[pyclass(
63356341
with(Constructor, Initializer, Representable, Destructor),
6336-
flags(BASETYPE, HAS_DICT)
6342+
flags(BASETYPE, HAS_DICT, HAS_WEAKREF)
63376343
)]
63386344
impl WindowsConsoleIO {
63396345
#[allow(dead_code)]

crates/vm/src/stdlib/sre.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ mod _sre {
212212
};
213213
}
214214

215-
#[pyclass(with(Hashable, Comparable, Representable))]
215+
#[pyclass(with(Hashable, Comparable, Representable), flags(HAS_WEAKREF))]
216216
impl Pattern {
217217
fn with_str<F, R>(string: &PyObject, vm: &VirtualMachine, f: F) -> PyResult<R>
218218
where

crates/vm/src/stdlib/thread.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub(crate) mod _thread {
132132
}
133133
}
134134

135-
#[pyclass(with(Constructor, Representable))]
135+
#[pyclass(with(Constructor, Representable), flags(HAS_WEAKREF))]
136136
impl Lock {
137137
#[pymethod]
138138
#[pymethod(name = "acquire_lock")]
@@ -205,7 +205,7 @@ pub(crate) mod _thread {
205205
}
206206
}
207207

208-
#[pyclass(with(Representable), flags(BASETYPE))]
208+
#[pyclass(with(Representable), flags(BASETYPE, HAS_WEAKREF))]
209209
impl RLock {
210210
#[pyslot]
211211
fn slot_new(cls: PyTypeRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult {

0 commit comments

Comments
 (0)