Skip to content

Commit

Permalink
add global module for python compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Riolo committed Apr 15, 2015
1 parent 5d1e368 commit c186493
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/martian/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import types


if hasattr(types, 'ClassType'):
CLASS_TYPES = (type, types.ClassType)
else:
CLASS_TYPES = (type,)
5 changes: 2 additions & 3 deletions src/martian/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
GlobalGrokker)
from martian.error import GrokError
from martian.martiandirective import component, priority
from martian.compat import CLASS_TYPES

@implementer(IMultiGrokker)
class MultiGrokkerBase(GrokkerBase):
Expand Down Expand Up @@ -180,9 +181,7 @@ def clear(self):
self._multi_global_grokker = MultiGlobalGrokker()

def grokkers(self, name, obj):
# python3 compatible
if isinstance(obj, type) or (hasattr(types, 'ClassType')
and isinstance(obj, types.ClassType)):
if isinstance(obj, CLASS_TYPES):
return self._multi_class_grokker.grokkers(name, obj)
elif isinstance(obj, types.ModuleType):
return self._multi_global_grokker.grokkers(name, obj)
Expand Down
5 changes: 2 additions & 3 deletions src/martian/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from zope import interface

import martian
from martian.compat import CLASS_TYPES
from martian.error import GrokError, GrokImportError

def not_unicode_or_ascii(value):
Expand All @@ -44,9 +45,7 @@ def not_unicode_or_ascii(value):
def isclass(obj):
"""We cannot use ``inspect.isclass`` because it will return True
for interfaces"""
# python3 compatible
return isinstance(obj, type) or (hasattr(types, 'ClassType') and
isinstance(obj, types.ClassType))
return isinstance(obj, CLASS_TYPES)


def check_subclass(obj, class_):
Expand Down

0 comments on commit c186493

Please sign in to comment.