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