1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-24 11:42:33 +01:00

[tests] add workaround for compile_expression_defaultdict in pypy3

This commit is contained in:
Mike Fährmann 2024-11-16 17:25:24 +01:00
parent f0419574a5
commit bced143750
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 10 additions and 2 deletions

View File

@ -705,7 +705,15 @@ def compile_expression_raw(expr, name="<expr>", globals=None):
def compile_expression_defaultdict(expr, name="<expr>", 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

View File

@ -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})