Skip to content

Commit b9be645

Browse files
committed
Improve nested context creation
1 parent 9e4e415 commit b9be645

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

pythonwhat/State.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ def __init__(self, context=None, prev=None):
2424
self._items = {**self.prev, **self.context.defined_items()}
2525

2626
def update_ctx(self, new_ctx):
27-
upd_prev = {**self.prev, **self.context.defined_items()}
28-
return self.__class__(new_ctx, upd_prev)
27+
return self.__class__(new_ctx, self._items)
2928

3029
def __getitem__(self, x):
3130
return self._items[x]
@@ -137,11 +136,11 @@ def update_context(name):
137136
if isinstance(kwargs.get("solution_ast", None), list):
138137
update_kwarg("solution_ast", wrap_in_module)
139138

140-
if "student_ast" in kwargs:
139+
if kwargs.get("student_ast", None):
141140
kwargs["student_code"] = self.student_ast_tokens.get_text(
142141
kwargs["student_ast"]
143142
)
144-
if "solution_ast" in kwargs:
143+
if kwargs.get("solution_ast", None):
145144
kwargs["solution_code"] = self.solution_ast_tokens.get_text(
146145
kwargs["solution_ast"]
147146
)

0 commit comments

Comments
 (0)