While learning Trac component architecture lesson that basically means
that "extension point plugin instance will be created with the same
ComponentManager where extension point provider is" I made some
adjustments to core.py to understand its structure.

Attached 0.11 branch diff changes __new__ to __init__ in component
metaclass to convey the idea that metaclass doesn't control the
component creation, but merely adjusts it and fills a registry. Some
other lines are changed to increase readability.

It would be nice to receive some feedback and to know whatever these
changes are worthy to be committed.

Happy Holidays!
-- 
--anatoly t.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac 
Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/trac-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Index: trac/core.py
===================================================================
--- trac/core.py	(revision 7768)
+++ trac/core.py	(working copy)
@@ -64,7 +64,7 @@
         point interface.
         """
         extensions = ComponentMeta._registry.get(self.interface, [])
-        return filter(None, [component.compmgr[cls] for cls in extensions])
+        return [component.compmgr[cls] for cls in extensions if cls]
 
     def __repr__(self):
         """Return a textual representation of the extension point."""
@@ -79,13 +79,12 @@
     _components = []
     _registry = {}
 
-    def __new__(cls, name, bases, d):
-        """Create the component class."""
+    def __init__(cls, name, bases, d):
+        """Tune created component class"""
 
-        new_class = type.__new__(cls, name, bases, d)
         if name == 'Component':
             # Don't put the Component base class in the registry
-            return new_class
+            return
 
         # Only override __init__ for Components not inheriting ComponentManager
         if True not in [issubclass(x, ComponentManager) for x in bases]:
@@ -96,11 +95,11 @@
             if not init:
                 # Because we're replacing the initializer, we need to make sure
                 # that any inherited initializers are also called.
-                for init in [b.__init__._original for b in new_class.mro()
+                for init in [b.__init__._original for b in cls.mro()
                              if issubclass(b, Component)
                              and '__init__' in b.__dict__]:
                     break
-            def maybe_init(self, compmgr, init=init, cls=new_class):
+            def maybe_init(self, compmgr, init=init, cls=cls):
                 if cls not in compmgr.components:
                     compmgr.components[cls] = self
                     if init:
@@ -110,23 +109,22 @@
                             del compmgr.components[cls]
                             raise
             maybe_init._original = init
-            new_class.__init__ = maybe_init
+            cls.__init__ = maybe_init
 
         if d.get('abstract'):
             # Don't put abstract component classes in the registry
-            return new_class
+            return
 
-        ComponentMeta._components.append(new_class)
+        ComponentMeta._components.append(cls)
         registry = ComponentMeta._registry
         for interface in d.get('_implements', []):
-            registry.setdefault(interface, []).append(new_class)
-        for base in [base for base in bases if hasattr(base, '_implements')]:
-            for interface in base._implements:
-                registry.setdefault(interface, []).append(new_class)
+            registry.setdefault(interface, []).append(cls)
+        for base in bases:
+            if hasattr(base, '_implements')]:
+                for interface in base._implements:
+                    registry.setdefault(interface, []).append(cls)
 
-        return new_class
 
-
 class Component(object):
     """Base class for components.
 

Reply via email to