##// END OF EJS Templates
Merge pull request #13825 from krassowski/fix-gh-13823...
Matthias Bussonnier -
r27881:cfe9e343 merge
parent child Browse files
Show More
@@ -671,6 +671,19 b' class MatcherAPIv2(Protocol):'
671 Matcher: TypeAlias = Union[MatcherAPIv1, MatcherAPIv2]
671 Matcher: TypeAlias = Union[MatcherAPIv1, MatcherAPIv2]
672
672
673
673
674 def has_any_completions(result: MatcherResult) -> bool:
675 """Check if any result includes any completions."""
676 if hasattr(result["completions"], "__len__"):
677 return len(result["completions"]) != 0
678 try:
679 old_iterator = result["completions"]
680 first = next(old_iterator)
681 result["completions"] = itertools.chain([first], old_iterator)
682 return True
683 except StopIteration:
684 return False
685
686
674 def completion_matcher(
687 def completion_matcher(
675 *, priority: float = None, identifier: str = None, api_version: int = 1
688 *, priority: float = None, identifier: str = None, api_version: int = 1
676 ):
689 ):
@@ -1952,7 +1965,7 b' class IPCompleter(Completer):'
1952 else:
1965 else:
1953 return []
1966 return []
1954
1967
1955 def python_matches(self, text:str)->List[str]:
1968 def python_matches(self, text: str) -> Iterable[str]:
1956 """Match attributes or global python names"""
1969 """Match attributes or global python names"""
1957 if "." in text:
1970 if "." in text:
1958 try:
1971 try:
@@ -2807,7 +2820,7 b' class IPCompleter(Completer):'
2807 should_suppress = (
2820 should_suppress = (
2808 (suppression_config is True)
2821 (suppression_config is True)
2809 or (suppression_recommended and (suppression_config is not False))
2822 or (suppression_recommended and (suppression_config is not False))
2810 ) and len(result["completions"])
2823 ) and has_any_completions(result)
2811
2824
2812 if should_suppress:
2825 if should_suppress:
2813 suppression_exceptions = result.get("do_not_suppress", set())
2826 suppression_exceptions = result.get("do_not_suppress", set())
@@ -1396,6 +1396,65 b' class TestCompleter(unittest.TestCase):'
1396 configure({"b_matcher": True})
1396 configure({"b_matcher": True})
1397 _("do not suppress", ["completion_b"])
1397 _("do not suppress", ["completion_b"])
1398
1398
1399 configure(True)
1400 _("do not suppress", ["completion_a"])
1401
1402 def test_matcher_suppression_with_iterator(self):
1403 @completion_matcher(identifier="matcher_returning_iterator")
1404 def matcher_returning_iterator(text):
1405 return iter(["completion_iter"])
1406
1407 @completion_matcher(identifier="matcher_returning_list")
1408 def matcher_returning_list(text):
1409 return ["completion_list"]
1410
1411 with custom_matchers([matcher_returning_iterator, matcher_returning_list]):
1412 ip = get_ipython()
1413 c = ip.Completer
1414
1415 def _(text, expected):
1416 c.use_jedi = False
1417 s, matches = c.complete(text)
1418 self.assertEqual(expected, matches)
1419
1420 def configure(suppression_config):
1421 cfg = Config()
1422 cfg.IPCompleter.suppress_competing_matchers = suppression_config
1423 c.update_config(cfg)
1424
1425 configure(False)
1426 _("---", ["completion_iter", "completion_list"])
1427
1428 configure(True)
1429 _("---", ["completion_iter"])
1430
1431 configure(None)
1432 _("--", ["completion_iter", "completion_list"])
1433
1434 def test_matcher_suppression_with_jedi(self):
1435 ip = get_ipython()
1436 c = ip.Completer
1437 c.use_jedi = True
1438
1439 def configure(suppression_config):
1440 cfg = Config()
1441 cfg.IPCompleter.suppress_competing_matchers = suppression_config
1442 c.update_config(cfg)
1443
1444 def _():
1445 with provisionalcompleter():
1446 matches = [completion.text for completion in c.completions("dict.", 5)]
1447 self.assertIn("keys", matches)
1448
1449 configure(False)
1450 _()
1451
1452 configure(True)
1453 _()
1454
1455 configure(None)
1456 _()
1457
1399 def test_matcher_disabling(self):
1458 def test_matcher_disabling(self):
1400 @completion_matcher(identifier="a_matcher")
1459 @completion_matcher(identifier="a_matcher")
1401 def a_matcher(text):
1460 def a_matcher(text):
General Comments 0
You need to be logged in to leave comments. Login now