Skip to content

Commit

Permalink
AssertImportHook.enabled predicate property
Browse files Browse the repository at this point in the history
  • Loading branch information
dag committed Feb 12, 2011
1 parent ca4b369 commit 699dea7
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions attest/hook.py
Expand Up @@ -189,6 +189,12 @@ def visit_Assert(self, node):
args=args, keywords=[], starargs=None, kwargs=None)), node)


class AssertImportHookEnabledDescriptor(object):

def __get__(self, instance, owner):
return any(isinstance(ih, owner) for ih in sys.meta_path)


class AssertImportHook(object):
"""A :term:`finder` and :term:`loader` that transforms imported modules
with :class:`AssertTransformer`.
Expand All @@ -197,6 +203,9 @@ class AssertImportHook(object):
"""

#: Class property, :const:`True` if the hook is enabled.
enabled = AssertImportHookEnabledDescriptor()

@classmethod
def enable(cls):
"""Enable the import hook."""
Expand Down

0 comments on commit 699dea7

Please sign in to comment.