Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r93583:cd23d604d4bc Date: 2017-12-27 07:47 +0100 http://bitbucket.org/pypy/pypy/changeset/cd23d604d4bc/
Log: struct.Struct() objects should be weakrefable diff --git a/pypy/module/struct/interp_struct.py b/pypy/module/struct/interp_struct.py --- a/pypy/module/struct/interp_struct.py +++ b/pypy/module/struct/interp_struct.py @@ -8,6 +8,7 @@ from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.error import OperationError, oefmt from pypy.interpreter.typedef import TypeDef, interp_attrproperty +from pypy.interpreter.typedef import make_weakref_descr from pypy.module.struct.formatiterator import ( PackFormatIterator, UnpackFormatIterator ) @@ -156,6 +157,7 @@ unpack=interp2app(W_Struct.descr_unpack), pack_into=interp2app(W_Struct.descr_pack_into), unpack_from=interp2app(W_Struct.descr_unpack_from), + __weakref__=make_weakref_descr(W_Struct), ) def clearcache(space): diff --git a/pypy/module/struct/test/test_struct.py b/pypy/module/struct/test/test_struct.py --- a/pypy/module/struct/test/test_struct.py +++ b/pypy/module/struct/test/test_struct.py @@ -432,6 +432,10 @@ assert s.unpack(s.pack(42)) == (42,) assert s.unpack_from(memoryview(s.pack(42))) == (42,) + def test_struct_weakrefable(self): + import weakref + weakref.ref(self.struct.Struct('i')) + def test_struct_subclass(self): class S(self.struct.Struct): def __init__(self): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit