From 4e68f9692f5e5095fddf9cb0b7480998e12500b1 Mon Sep 17 00:00:00 2001 From: Christophe de Vienne Date: Sun, 25 May 2014 00:02:47 +0200 Subject: [PATCH] Allow non-auto-registered complex type The default behavior of Base is to auto-register subclasses on their __registry__, which is itself auto-initialized with the default registry. This is a problem when we want to register the classes on a registry that is instanciated after the class definition (which is the case in cubicweb-wsme). With this patch this behavior can be inhibited by setting a 'None' or 'False' __registry__ to a class. Change-Id: Ia4bc3d295911b9dbaa8bd855fc0e61634e778a1d --- wsme/tests/test_types.py | 8 ++++++++ wsme/types.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/wsme/tests/test_types.py b/wsme/tests/test_types.py index c3805a2..486a781 100644 --- a/wsme/tests/test_types.py +++ b/wsme/tests/test_types.py @@ -629,3 +629,11 @@ Value: 'v3'. Value should be one of: v., v.", TempType.add_attributes(two=int) after = types.list_attributes(TempType) self.assertEqual(len(after), 2) + + def test_non_registered_complex_type(self): + class TempType(types.Base): + __registry__ = None + + self.assertFalse(types.iscomplex(TempType)) + types.registry.register(TempType) + self.assertTrue(types.iscomplex(TempType)) diff --git a/wsme/types.py b/wsme/types.py index 383dea6..a751abf 100644 --- a/wsme/types.py +++ b/wsme/types.py @@ -754,7 +754,7 @@ class BaseMeta(type): return type.__new__(cls, name, bases, dct) def __init__(cls, name, bases, dct): - if bases and bases[0] is not object: + if bases and bases[0] is not object and cls.__registry__: cls.__registry__.register(cls)