Deduplicate a set of completions. .. warning:: Unstable This function is unstable, API may change without warning. Parameters ---------- text: str text that should be completed. completions: Iterator[Completion] iterator over the completions to ded
(text: str, completions: _IC)
| 408 | |
| 409 | |
| 410 | def _deduplicate_completions(text: str, completions: _IC)-> _IC: |
| 411 | """ |
| 412 | Deduplicate a set of completions. |
| 413 | |
| 414 | .. warning:: Unstable |
| 415 | |
| 416 | This function is unstable, API may change without warning. |
| 417 | |
| 418 | Parameters |
| 419 | ---------- |
| 420 | text: str |
| 421 | text that should be completed. |
| 422 | completions: Iterator[Completion] |
| 423 | iterator over the completions to deduplicate |
| 424 | |
| 425 | Yields |
| 426 | ------ |
| 427 | `Completions` objects |
| 428 | |
| 429 | |
| 430 | Completions coming from multiple sources, may be different but end up having |
| 431 | the same effect when applied to ``text``. If this is the case, this will |
| 432 | consider completions as equal and only emit the first encountered. |
| 433 | |
| 434 | Not folded in `completions()` yet for debugging purpose, and to detect when |
| 435 | the IPython completer does return things that Jedi does not, but should be |
| 436 | at some point. |
| 437 | """ |
| 438 | completions = list(completions) |
| 439 | if not completions: |
| 440 | return |
| 441 | |
| 442 | new_start = min(c.start for c in completions) |
| 443 | new_end = max(c.end for c in completions) |
| 444 | |
| 445 | seen = set() |
| 446 | for c in completions: |
| 447 | new_text = text[new_start:c.start] + c.text + text[c.end:new_end] |
| 448 | if new_text not in seen: |
| 449 | yield c |
| 450 | seen.add(new_text) |
| 451 | |
| 452 | |
| 453 | def rectify_completions(text: str, completions: _IC, *, _debug=False)->_IC: |