diff --git a/_compatibility.py b/_compatibility.py index be8d0db8..cf41b37b 100644 --- a/_compatibility.py +++ b/_compatibility.py @@ -106,3 +106,9 @@ try: from functools import reduce except ImportError: reduce = reduce + +def use_metaclass(meta, *bases): + """ Create a class with a metaclass. """ + if not bases: + bases = (object,) + return meta("HackClass", bases, {}) diff --git a/dynamic.py b/dynamic.py index c465957e..9f8d988b 100644 --- a/dynamic.py +++ b/dynamic.py @@ -135,7 +135,7 @@ def dec(func): else: # must be instance stmt = element.var_args.parent_stmt() - print ' ' * counter + 'recursion,', stmt + print(' ' * counter + 'recursion,', stmt) counter += 1 res = func(*args, **kwargs) counter -= 1 diff --git a/evaluate.py b/evaluate.py index e877b2ca..08155bd3 100644 --- a/evaluate.py +++ b/evaluate.py @@ -19,7 +19,7 @@ TODO nonlocal statement, needed or can be ignored? TODO __ instance attributes should not be visible outside of the class. TODO getattr / __getattr__ / __getattribute__ ? """ -from _compatibility import next, property, hasattr, is_py3k +from _compatibility import next, property, hasattr, is_py3k, use_metaclass import sys import itertools @@ -266,13 +266,11 @@ class Instance(Executable): (self.__class__.__name__, self.base, len(self.var_args or [])) -class InstanceElement(object): +class InstanceElement(use_metaclass(CachedMetaClass)): """ InstanceElement is a wrapper for any object, that is used as an instance variable (e.g. self.variable or class methods). """ - __metaclass__ = CachedMetaClass - def __init__(self, instance, var): if isinstance(var, parsing.Function): var = Function(var)