Skip to content

Commit ad26417

Browse files
committed
clean up giant dict comp syntax
1 parent 4791fe5 commit ad26417

1 file changed

Lines changed: 6 additions & 14 deletions

File tree

pythonwhat/utils.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,12 @@ def copy_env(env, keep_objs=None):
3535
mutableTypes = (tuple, list, dict)
3636
# One list comprehension to filter list. Might need some cleaning, but it
3737
# works
38-
update_env = {
39-
key: copy.deepcopy(value) for key,
40-
value in env.items() if not (
41-
key.startswith("_") or isinstance(
42-
value,
43-
ModuleType) or key in [
44-
'In',
45-
'Out',
46-
'get_ipython',
47-
'quit',
48-
'exit']) and (
49-
key in keep_objs or isinstance(
50-
value,
51-
mutableTypes))}
38+
ipy_ignore = ['In', 'Out', 'get_ipython', 'quit', 'exit']
39+
update_env = { key: copy.deepcopy(value)
40+
for key, value in env.items()
41+
if not any((key.startswith("_"), isinstance(value, ModuleType), key in ipy_ignore))
42+
and ( key in keep_objs or isinstance( value, mutableTypes) )
43+
}
5244
updated_env = dict(env)
5345
updated_env.update(update_env)
5446
return(updated_env)

0 commit comments

Comments
 (0)