MCPcopy Index your code
hub / github.com/bpython/bpython / complete

Method complete

bpython/repl.py:769–821  ·  view source on GitHub ↗

Construct a full list of possible completions and display them in a window. Also check if there's an available argspec (via the inspect module) and bang that on top of the completions too. The return value is whether the list_win is visible or not. If no matches are

(self, tab: bool = False)

Source from the content-addressed store, hash-verified

767 # If example one match and tab=True, then choose that and clear matches
768
769 def complete(self, tab: bool = False) -> bool | None:
770 """Construct a full list of possible completions and
771 display them in a window. Also check if there's an available argspec
772 (via the inspect module) and bang that on top of the completions too.
773 The return value is whether the list_win is visible or not.
774
775 If no matches are found, just return whether there's an argspec to show
776 If any matches are found, save them and select the first one.
777
778 If tab is True exactly one match found, make the replacement and return
779 the result of running complete() again on the new line.
780 """
781
782 self.set_docstring()
783
784 matches, completer = autocomplete.get_completer(
785 self.completers,
786 cursor_offset=self.cursor_offset,
787 line=self.current_line,
788 locals_=cast(dict[str, Any], self.interp.locals),
789 argspec=self.funcprops,
790 current_block="\n".join(self.buffer + [self.current_line]),
791 complete_magic_methods=self.config.complete_magic_methods,
792 history=self.history,
793 )
794
795 if len(matches) == 0:
796 self.matches_iter.clear()
797 return bool(self.funcprops)
798
799 if completer:
800 self.matches_iter.update(
801 self.cursor_offset, self.current_line, matches, completer
802 )
803
804 if len(matches) == 1:
805 if tab:
806 # if this complete is being run for a tab key press, substitute
807 # common sequence
808 (
809 self._cursor_offset,
810 self._current_line,
811 ) = self.matches_iter.substitute_cseq()
812 return Repl.complete(self) # again for
813 elif self.matches_iter.current_word == matches[0]:
814 self.matches_iter.clear()
815 return False
816 return completer.shown_before_tab
817
818 else:
819 return tab or completer.shown_before_tab
820 else:
821 return False
822
823 def format_docstring(
824 self, docstring: str, width: int, height: int

Callers 15

_populate_completionMethod · 0.45
tabMethod · 0.45
matchesMethod · 0.45
matchesMethod · 0.45
test_import_emptyMethod · 0.45
test_importMethod · 0.45
test_import_blankMethod · 0.45
test_from_attributeMethod · 0.45

Calls 4

set_docstringMethod · 0.95
updateMethod · 0.80
substitute_cseqMethod · 0.80
clearMethod · 0.45

Tested by 15

test_import_emptyMethod · 0.36
test_importMethod · 0.36
test_import_blankMethod · 0.36
test_from_attributeMethod · 0.36
test_from_attr_moduleMethod · 0.36
test_from_packageMethod · 0.36