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

Class DictKeyCompletion

bpython/autocomplete.py:467–503  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

465
466
467class DictKeyCompletion(BaseCompletionType):
468 def matches(
469 self,
470 cursor_offset: int,
471 line: str,
472 *,
473 locals_: dict[str, Any] | None = None,
474 **kwargs: Any,
475 ) -> set[str] | None:
476 if locals_ is None:
477 return None
478
479 r = self.locate(cursor_offset, line)
480 if r is None:
481 return None
482 current_dict_parts = lineparts.current_dict(cursor_offset, line)
483 if current_dict_parts is None:
484 return None
485
486 dexpr = current_dict_parts.word
487 try:
488 obj = safe_eval(dexpr, locals_)
489 except EvaluationError:
490 return None
491 if isinstance(obj, dict) and obj.keys():
492 matches = {
493 f"{k!r}]" for k in obj.keys() if repr(k).startswith(r.word)
494 }
495 return matches if matches else None
496 else:
497 return None
498
499 def locate(self, cursor_offset: int, line: str) -> LinePart | None:
500 return lineparts.current_dict_key(cursor_offset, line)
501
502 def format(self, match: str) -> str:
503 return match[:-1]
504
505
506class MagicMethodCompletion(BaseCompletionType):

Callers 1

get_default_completerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected