MCPcopy Create free account
hub / github.com/bpython/bpython / get_completer

Function get_completer

bpython/autocomplete.py:719–778  ·  view source on GitHub ↗

Returns a list of matches and an applicable completer If no matches available, returns a tuple of an empty list and None cursor_offset is the current cursor column line is a string of the current line kwargs (all optional): locals_ is a dictionary of the environment

(
    completers: Sequence[BaseCompletionType],
    cursor_offset: int,
    line: str,
    *,
    locals_: dict[str, Any] | None = None,
    argspec: inspection.FuncProps | None = None,
    history: list[str] | None = None,
    current_block: str | None = None,
    complete_magic_methods: bool | None = None,
)

Source from the content-addressed store, hash-verified

717
718
719def get_completer(
720 completers: Sequence[BaseCompletionType],
721 cursor_offset: int,
722 line: str,
723 *,
724 locals_: dict[str, Any] | None = None,
725 argspec: inspection.FuncProps | None = None,
726 history: list[str] | None = None,
727 current_block: str | None = None,
728 complete_magic_methods: bool | None = None,
729) -> tuple[list[str], BaseCompletionType | None]:
730 """Returns a list of matches and an applicable completer
731
732 If no matches available, returns a tuple of an empty list and None
733
734 cursor_offset is the current cursor column
735 line is a string of the current line
736 kwargs (all optional):
737 locals_ is a dictionary of the environment
738 argspec is an inspection.FuncProps instance for the current function where
739 the cursor is
740 current_block is the possibly multiline not-yet-evaluated block of
741 code which the current line is part of
742 complete_magic_methods is a bool of whether we ought to complete
743 double underscore methods like __len__ in method signatures
744 """
745
746 def _cmpl_sort(x: str) -> tuple[bool, str]:
747 """
748 Function used to sort the matches.
749 """
750 # put parameters above everything in completion
751 return (
752 x[-1] != "=",
753 x,
754 )
755
756 for completer in completers:
757 try:
758 matches = completer.matches(
759 cursor_offset,
760 line,
761 locals_=locals_,
762 funcprops=argspec,
763 history=history,
764 current_block=current_block,
765 complete_magic_methods=complete_magic_methods,
766 )
767 except Exception as e:
768 # Instead of crashing the UI, log exceptions from autocompleters.
769 logger.debug(
770 "Completer %r failed with unhandled exception: %s", completer, e
771 )
772 continue
773 if matches is not None:
774 return sorted(matches, key=_cmpl_sort), (
775 completer if matches else None
776 )

Callers

nothing calls this directly

Calls 1

matchesMethod · 0.45

Tested by

no test coverage detected