diff --git a/hy/compiler.py b/hy/compiler.py index d71c5df..33a861b 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -729,15 +729,11 @@ class HyASTCompiler(object): elist = [HySymbol("hy_eval")] + [expr[0]] if len(expr) >= 2: - if not isinstance(expr[1], (HyDict, HySymbol)): - raise HyTypeError(expr, "Globals must be a dictionary") elist.append(expr[1]) else: elist.append(HyExpression([HySymbol("locals")])) if len(expr) == 3: - if not isinstance(expr[2], HyString): - raise HyTypeError(expr, "Module name must be a string") elist.append(expr[2]) else: elist.append(HyString(self.module_name)) diff --git a/hy/importer.py b/hy/importer.py index 7c8cb2f..bfe33e9 100644 --- a/hy/importer.py +++ b/hy/importer.py @@ -108,6 +108,15 @@ def hy_eval(hytree, namespace, module_name): foo.start_column = 0 foo.end_column = 0 replace_hy_obj(hytree, foo) + + try: + checktype = basestring + except NameError: + checktype = str + + if not isinstance(module_name, checktype): + raise HyTypeError(foo, "Module name must be a string") + _ast, expr = hy_compile(hytree, module_name, get_expr=True) # Spoof the positions in the generated ast... @@ -119,6 +128,9 @@ def hy_eval(hytree, namespace, module_name): node.lineno = 1 node.col_offset = 1 + if not isinstance(namespace, dict): + raise HyTypeError(foo, "Globals must be a dictionary") + # Two-step eval: eval() the body of the exec call eval(ast_compile(_ast, "", "exec"), namespace)