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:
parent
c8337025e9
commit
4e68f9692f
@ -629,3 +629,11 @@ Value: 'v3'. Value should be one of: v., v.",
|
|||||||
TempType.add_attributes(two=int)
|
TempType.add_attributes(two=int)
|
||||||
after = types.list_attributes(TempType)
|
after = types.list_attributes(TempType)
|
||||||
self.assertEqual(len(after), 2)
|
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))
|
||||||
|
@ -754,7 +754,7 @@ class BaseMeta(type):
|
|||||||
return type.__new__(cls, name, bases, dct)
|
return type.__new__(cls, name, bases, dct)
|
||||||
|
|
||||||
def __init__(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)
|
cls.__registry__.register(cls)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user