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

Class ExpressionAttributeCompletion

bpython/autocomplete.py:611–637  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

609
610
611class ExpressionAttributeCompletion(AttrCompletion):
612 # could replace attr completion as a more general case with some work
613 def locate(self, cursor_offset: int, line: str) -> LinePart | None:
614 return lineparts.current_expression_attribute(cursor_offset, line)
615
616 def matches(
617 self,
618 cursor_offset: int,
619 line: str,
620 *,
621 locals_: dict[str, Any] | None = None,
622 **kwargs: Any,
623 ) -> set[str] | None:
624 if locals_ is None:
625 locals_ = __main__.__dict__
626
627 attr = self.locate(cursor_offset, line)
628 assert attr, "locate was already truthy for the same call"
629
630 try:
631 obj = evaluate_current_expression(cursor_offset, line, locals_)
632 except EvaluationError:
633 return set()
634
635 # strips leading dot
636 matches = (m[1:] for m in self.attr_lookup(obj, "", attr.word))
637 return {m for m in matches if _few_enough_underscores(attr.word, m)}
638
639
640try:

Callers 1

get_default_completerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected