##// END OF EJS Templates
Merge pull request #10969 from takluyver/use-the-force...
Matthias Bussonnier -
r24129:7d533c31 merge
parent child Browse files
Show More
@@ -1101,14 +1101,6 b' class IPCompleter(Completer):'
1101 1101 #use this if positional argument name is also needed
1102 1102 #= re.compile(r'[\s|\[]*(\w+)(?:\s*=?\s*.*)')
1103 1103
1104 # All active matcher routines for completion
1105 self.matchers = [
1106 self.python_matches,
1107 self.file_matches,
1108 self.magic_matches,
1109 self.python_func_kw_matches,
1110 self.dict_key_matches,
1111 ]
1112 1104 self.magic_arg_matchers = [
1113 1105 self.magic_config_matches,
1114 1106 self.magic_color_matches,
@@ -1117,6 +1109,24 b' class IPCompleter(Completer):'
1117 1109 # This is set externally by InteractiveShell
1118 1110 self.custom_completers = None
1119 1111
1112 @property
1113 def matchers(self):
1114 """All active matcher routines for completion"""
1115 if self.use_jedi:
1116 return [
1117 self.file_matches,
1118 self.magic_matches,
1119 self.dict_key_matches,
1120 ]
1121 else:
1122 return [
1123 self.python_matches,
1124 self.file_matches,
1125 self.magic_matches,
1126 self.python_func_kw_matches,
1127 self.dict_key_matches,
1128 ]
1129
1120 1130 def all_completions(self, text):
1121 1131 """
1122 1132 Wrapper around the complete method for the benefit of emacs.
@@ -1931,7 +1941,7 b' class IPCompleter(Completer):'
1931 1941 return self._complete(line_buffer=line_buffer, cursor_pos=cursor_pos, text=text, cursor_line=0)[:2]
1932 1942
1933 1943 def _complete(self, *, cursor_line, cursor_pos, line_buffer=None, text=None,
1934 full_text=None, return_jedi_results=True) -> Tuple[str, List[str], List[str], Iterable[_FakeJediCompletion]]:
1944 full_text=None) -> Tuple[str, List[str], List[str], Iterable[_FakeJediCompletion]]:
1935 1945 """
1936 1946
1937 1947 Like complete but can also returns raw jedi completions as well as the
@@ -1997,7 +2007,7 b' class IPCompleter(Completer):'
1997 2007 # simply collapse the dict into a list for readline, but we'd have
1998 2008 # richer completion semantics in other evironments.
1999 2009 completions = ()
2000 if self.use_jedi and return_jedi_results:
2010 if self.use_jedi:
2001 2011 if not full_text:
2002 2012 full_text = line_buffer
2003 2013 completions = self._jedi_matches(
@@ -1985,6 +1985,7 b' class InteractiveShell(SingletonConfigurable):'
1985 1985 self.set_hook('complete_command', reset_completer, str_key = '%reset')
1986 1986
1987 1987
1988 @skip_doctest
1988 1989 def complete(self, text, line=None, cursor_pos=None):
1989 1990 """Return the completed text and a list of completions.
1990 1991
@@ -380,10 +380,13 b' def test_greedy_completions():'
380 380 "Shouldn't have completed on a[0]: %s"%c)
381 381 with greedy_completion(), provisionalcompleter():
382 382 def _(line, cursor_pos, expect, message, completion):
383 ip.Completer.use_jedi = False
383 384 _,c = ip.complete('.', line=line, cursor_pos=cursor_pos)
385 nt.assert_in(expect, c, message % c)
386
387 ip.Completer.use_jedi = True
384 388 with provisionalcompleter():
385 389 completions = ip.Completer.completions(line, cursor_pos)
386 nt.assert_in(expect, c, message%c)
387 390 nt.assert_in(completion, completions)
388 391
389 392 yield _, 'a[0].', 5, 'a[0].real', "Should have completed on a[0].: %s", Completion(5,5, 'real')
@@ -404,13 +407,14 b' def test_omit__names():'
404 407 cfg.IPCompleter.omit__names = 0
405 408 c.update_config(cfg)
406 409 with provisionalcompleter():
410 c.use_jedi = False
407 411 s,matches = c.complete('ip.')
408 completions = set(c.completions('ip.', 3))
409
410 412 nt.assert_in('ip.__str__', matches)
411 nt.assert_in(Completion(3, 3, '__str__'), completions)
412
413 413 nt.assert_in('ip._hidden_attr', matches)
414
415 c.use_jedi = True
416 completions = set(c.completions('ip.', 3))
417 nt.assert_in(Completion(3, 3, '__str__'), completions)
414 418 nt.assert_in(Completion(3,3, "_hidden_attr"), completions)
415 419
416 420
@@ -418,33 +422,37 b' def test_omit__names():'
418 422 cfg.IPCompleter.omit__names = 1
419 423 c.update_config(cfg)
420 424 with provisionalcompleter():
425 c.use_jedi = False
421 426 s,matches = c.complete('ip.')
422 completions = set(c.completions('ip.', 3))
423
424 427 nt.assert_not_in('ip.__str__', matches)
425 nt.assert_not_in(Completion(3,3,'__str__'), completions)
426
427 428 # nt.assert_in('ip._hidden_attr', matches)
429
430 c.use_jedi = True
431 completions = set(c.completions('ip.', 3))
432 nt.assert_not_in(Completion(3,3,'__str__'), completions)
428 433 nt.assert_in(Completion(3,3, "_hidden_attr"), completions)
429 434
430 435 cfg = Config()
431 436 cfg.IPCompleter.omit__names = 2
432 437 c.update_config(cfg)
433 438 with provisionalcompleter():
439 c.use_jedi = False
434 440 s,matches = c.complete('ip.')
435 completions = set(c.completions('ip.', 3))
436
437 441 nt.assert_not_in('ip.__str__', matches)
438 nt.assert_not_in(Completion(3,3,'__str__'), completions)
439
440 442 nt.assert_not_in('ip._hidden_attr', matches)
443
444 c.use_jedi = True
445 completions = set(c.completions('ip.', 3))
446 nt.assert_not_in(Completion(3,3,'__str__'), completions)
441 447 nt.assert_not_in(Completion(3,3, "_hidden_attr"), completions)
442 448
443 449 with provisionalcompleter():
450 c.use_jedi = False
444 451 s,matches = c.complete('ip._x.')
445 completions = set(c.completions('ip._x.', 6))
446
447 452 nt.assert_in('ip._x.keys', matches)
453
454 c.use_jedi = True
455 completions = set(c.completions('ip._x.', 6))
448 456 nt.assert_in(Completion(6,6, "keys"), completions)
449 457
450 458 del ip._hidden_attr
@@ -457,6 +465,7 b' def test_limit_to__all__False_ok():'
457 465 """
458 466 ip = get_ipython()
459 467 c = ip.Completer
468 c.use_jedi = False
460 469 ip.ex('class D: x=24')
461 470 ip.ex('d=D()')
462 471 cfg = Config()
@@ -483,6 +492,7 b' def test_get__all__entries_no__all__ok():'
483 492 def test_func_kw_completions():
484 493 ip = get_ipython()
485 494 c = ip.Completer
495 c.use_jedi = False
486 496 ip.ex('def myfunc(a=1,b=2): return a+b')
487 497 s, matches = c.complete(None, 'myfunc(1,b')
488 498 nt.assert_in('b=', matches)
@@ -573,6 +583,7 b' def test_magic_completion_order():'
573 583 def test_magic_completion_shadowing():
574 584 ip = get_ipython()
575 585 c = ip.Completer
586 c.use_jedi = False
576 587
577 588 # Before importing matplotlib, %matplotlib magic should be the only option.
578 589 text, matches = c.complete("mat")
@@ -1002,6 +1013,7 b' def test_from_module_completer():'
1002 1013
1003 1014 def test_snake_case_completion():
1004 1015 ip = get_ipython()
1016 ip.Completer.use_jedi = False
1005 1017 ip.user_ns['some_three'] = 3
1006 1018 ip.user_ns['some_four'] = 4
1007 1019 _, matches = ip.complete("s_", "print(s_f")
General Comments 0
You need to be logged in to leave comments. Login now