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
This commit is contained in:
Christophe de Vienne 2014-05-25 00:02:47 +02:00
parent c8337025e9
commit 4e68f9692f
2 changed files with 9 additions and 1 deletions

View File

@ -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))

View File

@ -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)