76
76
77
77
REOPEN_LAST_FILE = object ()
78
78
79
- assignment_pattern = re .compile (r'[^\[\]]+[^=]=[^=].+' )
80
- setitem_pattern = re .compile (r'(\w+)(\.i|\.iflat|\.points|\.ipoints)?\[.+\][^=]*=[^=].+' )
81
- history_vars_pattern = re .compile (r'_i?\d+' )
79
+ ASSIGNMENT_PATTERN = re .compile (r'[^\[\]]+[^=]=[^=].+' )
80
+ SUBSET_UPDATE_PATTERN = re .compile (r'(\w+)'
81
+ r'(\.i|\.iflat|\.points|\.ipoints)?'
82
+ r'\[.+\]\s*'
83
+ r'([-+*/%&|^><]|//|\*\*|>>|<<)?'
84
+ r'=\s*[^=].*' )
85
+ HISTORY_VARS_PATTERN = re .compile (r'_i?\d+' )
82
86
# XXX: add all scalars except strings (from numpy or plain Python)?
83
87
# (long) strings are not handled correctly so should NOT be in this list
84
88
# tuple, list
@@ -668,7 +672,7 @@ def delete_current_item(self):
668
672
def line_edit_update (self ):
669
673
import larray as la
670
674
last_input = self .eval_box .text ()
671
- if assignment_pattern .match (last_input ):
675
+ if ASSIGNMENT_PATTERN .match (last_input ):
672
676
context = self .data ._objects .copy ()
673
677
exec (last_input , la .__dict__ , context )
674
678
varname = self .update_mapping (context )
@@ -690,13 +694,13 @@ def ipython_cell_executed(self):
690
694
ip_keys = {'In' , 'Out' , '_' , '__' , '___' , '__builtin__' , '_dh' , '_ih' , '_oh' , '_sh' , '_i' , '_ii' , '_iii' ,
691
695
'exit' , 'get_ipython' , 'quit' }
692
696
# '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__',
693
- clean_ns = {k : v for k , v in user_ns .items () if k not in ip_keys and not history_vars_pattern .match (k )}
697
+ clean_ns = {k : v for k , v in user_ns .items () if k not in ip_keys and not HISTORY_VARS_PATTERN .match (k )}
694
698
695
699
# user_ns['_i'] is not updated yet (refers to the -2 item)
696
700
# 'In' and '_ih' point to the same object (but '_ih' is supposed to be the non-overridden one)
697
701
cur_input_num = len (user_ns ['_ih' ]) - 1
698
702
last_input = user_ns ['_ih' ][- 1 ]
699
- setitem_match = setitem_pattern .match (last_input )
703
+ setitem_match = SUBSET_UPDATE_PATTERN .match (last_input )
700
704
if setitem_match :
701
705
varname = setitem_match .group (1 )
702
706
# setitem to (i)python special variables do not concern us
0 commit comments