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

Method matches

bpython/autocomplete.py:535–568  ·  view source on GitHub ↗

Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match.

(
        self,
        cursor_offset: int,
        line: str,
        *,
        locals_: dict[str, Any] | None = None,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

533
534class GlobalCompletion(BaseCompletionType):
535 def matches(
536 self,
537 cursor_offset: int,
538 line: str,
539 *,
540 locals_: dict[str, Any] | None = None,
541 **kwargs: Any,
542 ) -> set[str] | None:
543 """Compute matches when text is a simple name.
544 Return a list of all keywords, built-in functions and names currently
545 defined in self.namespace that match.
546 """
547 if locals_ is None:
548 return None
549
550 r = self.locate(cursor_offset, line)
551 if r is None:
552 return None
553
554 n = len(r.word)
555 matches = {
556 word for word in KEYWORDS if self.method_match(word, n, r.word)
557 }
558 for nspace in (builtins.__dict__, locals_):
559 for word, val in nspace.items():
560 # if identifier isn't ascii, don't complete (syntax error)
561 if word is None:
562 continue
563 if (
564 self.method_match(word, n, r.word)
565 and word != "__builtins__"
566 ):
567 matches.add(_callable_postfix(val, word))
568 return matches if matches else None
569
570 def locate(self, cursor_offset: int, line: str) -> LinePart | None:
571 return lineparts.current_single_word(cursor_offset, line)

Callers

nothing calls this directly

Calls 3

locateMethod · 0.95
_callable_postfixFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected