MCPcopy Index your code
hub / github.com/ipython/ipython / check_complete

Method check_complete

IPython/core/inputtransformer2.py:736–875  ·  view source on GitHub ↗

Return whether a block of code is ready to execute, or should be continued Parameters ---------- cell : string Python input code, which can be multiline. Returns ------- status : str One of 'complete', 'incomplete', or 'invali

(self, cell: str)

Source from the content-addressed store, hash-verified

734 return ''.join(lines)
735
736 def check_complete(self, cell: str):
737 """Return whether a block of code is ready to execute, or should be continued
738
739 Parameters
740 ----------
741 cell : string
742 Python input code, which can be multiline.
743
744 Returns
745 -------
746 status : str
747 One of 'complete', 'incomplete', or 'invalid' if source is not a
748 prefix of valid code.
749 indent_spaces : int or None
750 The number of spaces by which to indent the next line of code. If
751 status is not 'incomplete', this is None.
752 """
753 # Remember if the lines ends in a new line.
754 ends_with_newline = False
755 for character in reversed(cell):
756 if character == '\n':
757 ends_with_newline = True
758 break
759 elif character.strip():
760 break
761 else:
762 continue
763
764 if not ends_with_newline:
765 # Append an newline for consistent tokenization
766 # See https://bugs.python.org/issue33899
767 cell += '\n'
768
769 lines = cell.splitlines(keepends=True)
770
771 if not lines:
772 return 'complete', None
773
774 for line in reversed(lines):
775 if not line.strip():
776 continue
777 elif line.strip("\n").endswith("\\"):
778 return "incomplete", find_last_indent(lines)
779 else:
780 break
781
782 try:
783 for transform in self.cleanup_transforms:
784 if not getattr(transform, 'has_side_effects', False):
785 lines = transform(lines)
786 except SyntaxError:
787 return 'invalid', None
788
789 if lines[0].startswith('%%'):
790 # Special case for cell magics - completion marked by blank line
791 if lines[-1].strip():
792 return 'incomplete', find_last_indent(lines)
793 else:

Callers 2

test_side_effects_IFunction · 0.95
test_side_effects_IIFunction · 0.95

Calls 5

do_token_transformsMethod · 0.95
find_last_indentFunction · 0.85
make_tokens_by_lineFunction · 0.85
has_sunken_bracketsFunction · 0.85
popMethod · 0.80

Tested by 2

test_side_effects_IFunction · 0.76
test_side_effects_IIFunction · 0.76