[Grok-dev] Re: Martian and ExtensionClasses.

Martijn Faassen faassen at startifact.com
Sun Apr 27 12:51:00 EDT 2008

Lennart Regebro wrote:
> When writing the changelog for the EventClass support I realized maybe
> this was useful for metclasses as well.
> So I asked on #python and Thomas Wouters in his useful style of
> helpful rudeness recommended that we don't do type(obj) at all, but
> that we do
> isinstance(obj, ...). So I tried that:
>     def grokkers(self, name, obj):
>         obj_type = type(obj)
>         if isinstance(obj, (type, types.ClassType)):
>             return self._multi_class_grokker.grokkers(name, obj)
>         elif isinstance(obj, types.ModuleType):
>             return self._multi_global_grokker.grokkers(name, obj)
>         else:
>             return self._multi_instance_grokker.grokkers(name, obj)
> This works with ExtensionClasses, and it is supposed to work with
> metaclasses as well.
> So question to Martijn: Is there any reason you used type(obj) instead
> of isinstance(obj, ...) ? It seems like with this change we don't need
> to extend the list of classes.

No particular reason. I hadn't thought of using isinstance on classes, 
but classes are instances of meta-classes so I imagine that does work.

What's obj_type still doing there, by the way? You don't seem to use it.



More information about the Grok-dev mailing list