diff --git a/gallery_dl/util.py b/gallery_dl/util.py index 44ac22e2..3cbe5107 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -705,7 +705,15 @@ def compile_expression_raw(expr, name="", globals=None): def compile_expression_defaultdict(expr, name="", globals=None): global GLOBALS_DEFAULT - GLOBALS_DEFAULT = collections.defaultdict(lambda: NONE, GLOBALS) + + if isinstance(__builtins__, dict): + # cpython + GLOBALS_DEFAULT = collections.defaultdict(lambda n=NONE: n, GLOBALS) + else: + # pypy3 - insert __builtins__ symbols into globals dict + GLOBALS_DEFAULT = collections.defaultdict( + lambda n=NONE: n, __builtins__.__dict__) + GLOBALS_DEFAULT.update(GLOBALS) global compile_expression_defaultdict compile_expression_defaultdict = compile_expression_defaultdict_impl diff --git a/test/test_util.py b/test/test_util.py index 0a9ff423..fa16c443 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -328,7 +328,7 @@ class TestCompileExpression(unittest.TestCase): with self.assertRaises(NameError): expr({"a": 2}) - expr = util.compile_expression_defaultdict("int.param") + expr = util.compile_expression_raw("int.param") with self.assertRaises(AttributeError): expr({"a": 2})