From 4840a0f46d5e50990509757fbda4e6c6bc5ac76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 23 Sep 2021 23:12:35 +0200 Subject: [PATCH] Ensure that objects in the Pool has __slots__ issue10719 review375361002 --- CHANGELOG | 1 + trytond/ir/avatar.py | 1 + trytond/model/avatar.py | 2 +- trytond/tests/mixin.py | 8 ++++---- trytond/tests/test_tryton.py | 16 ++++++++++++++++ 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c58b26e1ce..c56e892bd6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Ensure with a test that objects in the Pool have __slots__ * Use bigdecimal tag for XML-RPC * Use tuple in Dict value instead of list * Do not set record name on title of report get_email diff --git a/trytond/ir/avatar.py b/trytond/ir/avatar.py index c1cc8c0616..4245b176b6 100644 --- a/trytond/ir/avatar.py +++ b/trytond/ir/avatar.py @@ -32,6 +32,7 @@ FONT = os.path.join(os.path.dirname(__file__), 'fonts', 'karla.ttf') class ImageMixin: + __slots__ = () image = fields.Binary( "Image", file_id=file_id, store_prefix=store_prefix) image_id = fields.Char("Image ID", readonly=True) diff --git a/trytond/model/avatar.py b/trytond/model/avatar.py index 78c846f368..9fb7e3e182 100644 --- a/trytond/model/avatar.py +++ b/trytond/model/avatar.py @@ -8,7 +8,7 @@ from trytond.pool import Pool def avatar_mixin(size=64, default=None): class AvatarMixin: - + __slots__ = () avatars = fields.One2Many( 'ir.avatar', 'resource', lazy_gettext('ir.msg_avatars'), size=1) avatar = fields.Function( diff --git a/trytond/tests/mixin.py b/trytond/tests/mixin.py index e498f45441..6fdd952d11 100644 --- a/trytond/tests/mixin.py +++ b/trytond/tests/mixin.py @@ -6,19 +6,19 @@ from trytond.report import Report class TestMixin: - pass + __slots__ = () class TestSecondMixin: - pass + __slots__ = () class NotMixin: - pass + __slots__ = () class ReportMixin: - pass + __slots__ = () class DeactivableModelView(DeactivableMixin, ModelView): diff --git a/trytond/tests/test_tryton.py b/trytond/tests/test_tryton.py index 1d645a5846..3573f3492c 100644 --- a/trytond/tests/test_tryton.py +++ b/trytond/tests/test_tryton.py @@ -744,6 +744,22 @@ class ModuleTestCase(unittest.TestCase): msg="ModelSingleton must appear before ModelSQL in the parent " "classes of '%s'." % mname) + @with_transaction() + def test_pool_slots(self): + "Test pool object has __slots__" + for type_ in ['model', 'wizard', 'report']: + for name, cls in Pool().iterobject(type_): + if not isregisteredby(cls, self.module): + continue + if getattr(cls, '__no_slots__', None): + continue + for kls in cls.__mro__: + if kls is object: + continue + self.assertTrue(hasattr(kls, '__slots__'), + msg="The %s of %s '%s' has no __slots__" + % (kls, type_, name)) + @with_transaction() def test_buttons_registered(self): 'Test all buttons are registered in ir.model.button'