Show More
@@ -445,9 +445,13 b' class InputSplitter(object):' | |||
|
445 | 445 | if not self._full_dedent: |
|
446 | 446 | return False |
|
447 | 447 | else: |
|
448 | nblocks = len(split_blocks(''.join(self._buffer))) | |
|
449 | if nblocks==1: | |
|
448 | try: | |
|
449 | nodes = self.ast_nodes() | |
|
450 | except Exception: | |
|
450 | 451 | return False |
|
452 | else: | |
|
453 | if len(nodes) == 1: | |
|
454 | return False | |
|
451 | 455 | |
|
452 | 456 | # When input is complete, then termination is marked by an extra blank |
|
453 | 457 | # line at the end. |
@@ -535,6 +539,23 b' class InputSplitter(object):' | |||
|
535 | 539 | # python syntax, feed it back a second time through the AST-based |
|
536 | 540 | # splitter, which is more accurate than ours. |
|
537 | 541 | return split_blocks(''.join(blocks)) |
|
542 | ||
|
543 | def ast_nodes(self, lines=None): | |
|
544 | """Turn the lines into a list of AST nodes. | |
|
545 | ||
|
546 | Parameters | |
|
547 | ---------- | |
|
548 | lines : str | |
|
549 | A (possibly multiline) string of Python code. If None (default), it | |
|
550 | will use the InputSplitter's current code buffer. | |
|
551 | ||
|
552 | Returns | |
|
553 | ------- | |
|
554 | A list of AST (abstract syntax tree) nodes representing the code. | |
|
555 | """ | |
|
556 | if lines is None: | |
|
557 | lines = u"".join(self._buffer) | |
|
558 | return ast.parse(lines).body | |
|
538 | 559 | |
|
539 | 560 | #------------------------------------------------------------------------ |
|
540 | 561 | # Private interface |
General Comments 0
You need to be logged in to leave comments.
Login now