[Grok-dev] Grok in Zope 2: Paris Sprint first day wrap up: Success! (Kinda)

Brandon Craig Rhodes brandon at rhodesmill.org
Sat Apr 26 10:11:28 EDT 2008

"Lennart Regebro" <regebro at gmail.com> writes:

> try:
>     from ExtensionClass import ExtensionClass
> except ImportError:
>     ExtensionClass = types.ClassType
> and then change a line in MultiGrokker.grokkers from
>         if obj_type in (type, types.ClassType):
> to
>         if obj_type in (type, types.ClassType, ExtensionClass):

This strikes me as ugly and, in its admittedly small way, confusing
and inefficient:

 (a) ExtensionClass will be pulled in merely because it exists, not
     because the user is actually trying to use it in this app.

 (b) If ExtensionClass does not exist, then the symbol becomes
     available anyway but means something quite different from what
     it says.

 (c) If ExtensionClass is not available, you wind up comparing the
     obj_type against the same value *twice*.

I know these are all very minor, but a sense of style demands that we
really solve the problem.  First, early in the module, we should say:

_ClassTypes = set([ type, types.ClassType ])

def register_class_type(t):

and then we should make the code down in MultiGrokker say:

        if obj_type in _ClassTypes:

and, finally, the user's activation of five.grok in his code (on
import, maybe?) should call register_class_type(ExtensionType).
Martian does not need to gain special knowledge of every single other
framework that it might get linked to in the future that requires a
special rule.  *Especially* when it "detects" the other framework
through trying to import it itself, when the user might not even be
using it in ths current application!

Brandon Craig Rhodes   brandon at rhodesmill.org   http://rhodesmill.org/brandon

More information about the Grok-dev mailing list