Skip to content

Commit

Permalink
[tests] add workaround for compile_expression_defaultdict in pypy3
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Nov 16, 2024
1 parent f041957 commit bced143
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion gallery_dl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def test_compile_expression_raw(self):
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})

Expand Down

0 comments on commit bced143

Please sign in to comment.