[Checkins] SVN: martian/trunk/ Use isinstance() instead of type()
when checking for classes seems to work also with
Lennart Regebro
regebro at gmail.com
Sun Apr 27 07:17:46 EDT 2008
Log message for revision 85785:
Use isinstance() instead of type() when checking for classes seems to work also with
ExtensionClasses and is supposed to work with metaclasses.
Changed:
U martian/trunk/CHANGES.txt
U martian/trunk/src/martian/core.py
-=-
Modified: martian/trunk/CHANGES.txt
===================================================================
--- martian/trunk/CHANGES.txt 2008-04-27 10:58:48 UTC (rev 85784)
+++ martian/trunk/CHANGES.txt 2008-04-27 11:17:45 UTC (rev 85785)
@@ -11,9 +11,13 @@
allows the grokking of views in test code using Grok's
``grok.testing.grok_component`` without a failure when it sets up the
``static`` attribute.
+
* no longer use the convention that classes ending in -Base will be considered
base classes. You must now explicitly use the grok.baseclass() directive.
+* The type check of classes uses isinstance() instead of type(). This means
+ Grok can work with Zope 2 ExtensionClasses and metaclass programming.
+
0.9.3 (2008-01-26)
==================
Modified: martian/trunk/src/martian/core.py
===================================================================
--- martian/trunk/src/martian/core.py 2008-04-27 10:58:48 UTC (rev 85784)
+++ martian/trunk/src/martian/core.py 2008-04-27 11:17:45 UTC (rev 85785)
@@ -8,12 +8,7 @@
GlobalGrokker)
from martian.error import GrokError
-try:
- from ExtensionClass import ExtensionClass
- CLASS_TYPES = (type, types.ClassType, ExtensionClass)
-except ImportError:
- CLASS_TYPES = (type, types.ClassType)
-
+
class MultiGrokkerBase(GrokkerBase):
implements(IMultiGrokker)
@@ -176,10 +171,9 @@
self._multi_global_grokker = MultiGlobalGrokker()
def grokkers(self, name, obj):
- obj_type = type(obj)
- if obj_type in CLASS_TYPES:
+ if isinstance(obj, (type, types.ClassType)):
return self._multi_class_grokker.grokkers(name, obj)
- elif obj_type is types.ModuleType:
+ elif isinstance(obj, types.ModuleType):
return self._multi_global_grokker.grokkers(name, obj)
else:
return self._multi_instance_grokker.grokkers(name, obj)
More information about the Checkins
mailing list