Scott Sanders wrote:
>> I'm not entirely clear what you are thinking. Right now the registry
>> tracks classes, but it never returns classes. Instead class
>> references are pushed into the places they are needed, using callbacks
>> which are triggered on class creation. So I'm not sure where this
>> would fit.
>
>
> The registry always returns a class when asked (for classes in joins,
> etc), or am I just smoking something??? I understand it never
> generates a class.
The registry is meant to deal with circular references, which is why it
doesn't return classes at all. Since if A depends on B, and B depends
on A, the calls will look like:
class A:
my_b = registry.getClass('B') # registry goes off and creates B...
class B:
my_a = registry.getClass('A') # but A doesn't exist yet, and
# it won't until B is finished being created
Instead it works like:
import classregistry
registry = classregistry.registry('default')
class A:
pass
registry.addClassCallback('B', lambda cls: A.my_b = cls)
registry.addClass(A)
# So far the registry hasn't done anything at all
class B:
pass
registry.addClassCallback('A', lambda cls: B.my_a = cls)
# The registry immediately calls that lambda passing in A
registry.addClass(B)
# The registry now calls the previous lambda, passing in B
Maybe it would be helpful if the registry had a method to return the
names of all the classes that are still pending? That would be:
def pendingClasses(self):
return self.callbacks.keys()
After you've loaded a class, you could check if there were any pending
classes, and try to load them up.
--
Ian Bicking / ia...@co... / http://blog.ianbicking.org
|