From f705290f0d43ca4bde75fc18f10790faf8c01226 Mon Sep 17 00:00:00 2001 From: Daniel Havlik Date: Thu, 14 Sep 2017 13:24:50 +0200 Subject: [PATCH 1/3] Change checking for type of expression context to an assert. Name expression can only be Load, so that the if makes no sense. --- src/RestrictedPython/Eval.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/RestrictedPython/Eval.py b/src/RestrictedPython/Eval.py index 836ea5e..75805ce 100644 --- a/src/RestrictedPython/Eval.py +++ b/src/RestrictedPython/Eval.py @@ -85,8 +85,10 @@ def prepUnrestrictedCode(self): used = set() for node in ast.walk(exp_node): if isinstance(node, ast.Name): - if isinstance(node.ctx, ast.Load): - used.add(node.id) + # Because there are now Name expressions which context + # is *not* Load, we changed the if here to an assert. + assert isinstance(node.ctx, ast.Load) + used.add(node.id) self.used = tuple(used) From f659c5f4ab4a82e3f8ad626900f5040bac542e89 Mon Sep 17 00:00:00 2001 From: Daniel Havlik Date: Thu, 14 Sep 2017 14:49:17 +0200 Subject: [PATCH 2/3] typo --- src/RestrictedPython/Eval.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RestrictedPython/Eval.py b/src/RestrictedPython/Eval.py index 75805ce..0c16067 100644 --- a/src/RestrictedPython/Eval.py +++ b/src/RestrictedPython/Eval.py @@ -85,7 +85,7 @@ def prepUnrestrictedCode(self): used = set() for node in ast.walk(exp_node): if isinstance(node, ast.Name): - # Because there are now Name expressions which context + # Because there are no Name expressions which context # is *not* Load, we changed the if here to an assert. assert isinstance(node.ctx, ast.Load) used.add(node.id) From c5df0c3cbc1e3d1fd2a85f79ea9d0544714bf338 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Thu, 14 Sep 2017 16:54:36 +0200 Subject: [PATCH 3/3] Update comment [skip ci] --- src/RestrictedPython/Eval.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/RestrictedPython/Eval.py b/src/RestrictedPython/Eval.py index 0c16067..8d52bbd 100644 --- a/src/RestrictedPython/Eval.py +++ b/src/RestrictedPython/Eval.py @@ -85,8 +85,8 @@ def prepUnrestrictedCode(self): used = set() for node in ast.walk(exp_node): if isinstance(node, ast.Name): - # Because there are no Name expressions which context - # is *not* Load, we changed the if here to an assert. + # As we are in 'eval' mode here, no other contexts + # should be possible, but who knows: assert isinstance(node.ctx, ast.Load) used.add(node.id)