Show More
@@ -340,20 +340,14 b' class InputSplitter(object):' | |||||
340 | This method is meant to be used by line-oriented frontends, who need to |
|
340 | This method is meant to be used by line-oriented frontends, who need to | |
341 | guess whether a block is complete or not based solely on prior and |
|
341 | guess whether a block is complete or not based solely on prior and | |
342 | current input lines. The InputSplitter considers it has a complete |
|
342 | current input lines. The InputSplitter considers it has a complete | |
343 |
interactive block and will not accept more input |
|
343 | interactive block and will not accept more input when either: | |
344 | SyntaxError is raised, or *all* of the following are true: |
|
|||
345 |
|
344 | |||
346 | 1. The input compiles to a complete statement. |
|
345 | * A SyntaxError is raised | |
347 |
|
346 | |||
348 | 2. The indentation level is flush-left (because if we are indented, |
|
347 | * The code is complete and consists of a single line or a single | |
349 | like inside a function definition or for loop, we need to keep |
|
348 | non-compound statement | |
350 | reading new input). |
|
|||
351 |
|
349 | |||
352 | 3. There is one extra line consisting only of whitespace. |
|
350 | * The code is complete and has a blank line at the end | |
353 |
|
||||
354 | Because of condition #3, this method should be used only by |
|
|||
355 | *line-oriented* frontends, since it means that intermediate blank lines |
|
|||
356 | are not allowed in function definitions (or any other indented block). |
|
|||
357 |
|
351 | |||
358 | If the current input produces a syntax error, this method immediately |
|
352 | If the current input produces a syntax error, this method immediately | |
359 | returns False but does *not* raise the syntax error exception, as |
|
353 | returns False but does *not* raise the syntax error exception, as | |
@@ -374,10 +368,13 b' class InputSplitter(object):' | |||||
374 | #print("Blank line") # debug |
|
368 | #print("Blank line") # debug | |
375 | return False |
|
369 | return False | |
376 |
|
370 | |||
377 |
# If there's just a single AST node, and we're flush left, as is |
|
371 | # If there's just a single line or AST node, and we're flush left, as is | |
378 | # case after a simple statement such as 'a=1', we want to execute it |
|
372 | # the case after a simple statement such as 'a=1', we want to execute it | |
379 | # straight away. |
|
373 | # straight away. | |
380 | if self.indent_spaces==0: |
|
374 | if self.indent_spaces==0: | |
|
375 | if len(self.source.splitlines()) <= 1: | |||
|
376 | return False | |||
|
377 | ||||
381 | try: |
|
378 | try: | |
382 | code_ast = ast.parse(u''.join(self._buffer)) |
|
379 | code_ast = ast.parse(u''.join(self._buffer)) | |
383 | except Exception: |
|
380 | except Exception: |
General Comments 0
You need to be logged in to leave comments.
Login now