MCPcopy Create free account
hub / github.com/ipython/ipython / Completion

Class Completion

IPython/core/completer.py:347–404  ·  view source on GitHub ↗

Completion object used and return by IPython completers. .. warning:: Unstable This function is unstable, API may change without warning. It will also raise unless use in proper context manager. This act as a middle ground :any:`Completion` object between the :any

Source from the content-addressed store, hash-verified

345
346
347class Completion:
348 """
349 Completion object used and return by IPython completers.
350
351 .. warning:: Unstable
352
353 This function is unstable, API may change without warning.
354 It will also raise unless use in proper context manager.
355
356 This act as a middle ground :any:`Completion` object between the
357 :any:`jedi.api.classes.Completion` object and the Prompt Toolkit completion
358 object. While Jedi need a lot of information about evaluator and how the
359 code should be ran/inspected, PromptToolkit (and other frontend) mostly
360 need user facing information.
361
362 - Which range should be replaced replaced by what.
363 - Some metadata (like completion type), or meta information to displayed to
364 the use user.
365
366 For debugging purpose we can also store the origin of the completion (``jedi``,
367 ``IPython.python_matches``, ``IPython.magics_matches``...).
368 """
369
370 __slots__ = ['start', 'end', 'text', 'type', 'signature', '_origin']
371
372 def __init__(self, start: int, end: int, text: str, *, type: str=None, _origin='', signature='') -> None:
373 warnings.warn("``Completion`` is a provisional API (as of IPython 6.0). "
374 "It may change without warnings. "
375 "Use in corresponding context manager.",
376 category=ProvisionalCompleterWarning, stacklevel=2)
377
378 self.start = start
379 self.end = end
380 self.text = text
381 self.type = type
382 self.signature = signature
383 self._origin = _origin
384
385 def __repr__(self):
386 return '<Completion start=%s end=%s text=%r type=%r, signature=%r,>' % \
387 (self.start, self.end, self.text, self.type or '?', self.signature or '?')
388
389 def __eq__(self, other)->Bool:
390 """
391 Equality and hash do not hash the type (as some completer may not be
392 able to infer the type), but are use to (partially) de-duplicate
393 completion.
394
395 Completely de-duplicating completion is a bit tricker that just
396 comparing as it depends on surrounding text, which Completions are not
397 aware of.
398 """
399 return self.start == other.start and \
400 self.end == other.end and \
401 self.text == other.text
402
403 def __hash__(self):
404 return hash((self.start, self.end, self.text))

Callers 6

_test_completeMethod · 0.90
_test_not_completeMethod · 0.90
_get_completionsMethod · 0.85
rectify_completionsFunction · 0.85
_completionsMethod · 0.85

Calls

no outgoing calls

Tested by 3

_test_completeMethod · 0.72
_test_not_completeMethod · 0.72