##// END OF EJS Templates
Fix bug where 'if 1:' was being added to comment-only code....
Fernando Perez -
Show More
@@ -103,6 +103,10 b" ESC_PAREN = '/'"
103 dedent_re = re.compile(r'^\s+raise|^\s+return|^\s+pass')
103 dedent_re = re.compile(r'^\s+raise|^\s+return|^\s+pass')
104 ini_spaces_re = re.compile(r'^([ \t\r\f\v]+)')
104 ini_spaces_re = re.compile(r'^([ \t\r\f\v]+)')
105
105
106 # regexp to match pure comment lines so we don't accidentally insert 'if 1:'
107 # before pure comments
108 comment_line_re = re.compile('^\s*\#')
109
106
110
107 def num_ini_spaces(s):
111 def num_ini_spaces(s):
108 """Return the number of initial spaces in a string.
112 """Return the number of initial spaces in a string.
@@ -368,7 +372,9 b' class InputSplitter(object):'
368 # this allows execution of indented pasted code. It is tempting
372 # this allows execution of indented pasted code. It is tempting
369 # to add '\n' at the end of source to run commands like ' a=1'
373 # to add '\n' at the end of source to run commands like ' a=1'
370 # directly, but this fails for more complicated scenarios
374 # directly, but this fails for more complicated scenarios
371 if not self._buffer and lines[:1] in [' ', '\t']:
375
376 if not self._buffer and lines[:1] in [' ', '\t'] and \
377 not comment_line_re.match(lines):
372 lines = 'if 1:\n%s' % lines
378 lines = 'if 1:\n%s' % lines
373
379
374 self._store(lines)
380 self._store(lines)
General Comments 0
You need to be logged in to leave comments. Login now