Show More
@@ -1101,28 +1101,31 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 |
|
1104 | self.magic_arg_matchers = [ | |
|
1105 | self.magic_config_matches, | |||
|
1106 | self.magic_color_matches, | |||
|
1107 | ] | |||
|
1108 | ||||
|
1109 | # This is set externally by InteractiveShell | |||
|
1110 | self.custom_completers = None | |||
|
1111 | ||||
|
1112 | @property | |||
|
1113 | def matchers(self): | |||
|
1114 | """All active matcher routines for completion""" | |||
1105 | if self.use_jedi: |
|
1115 | if self.use_jedi: | |
1106 |
|
|
1116 | return [ | |
1107 | self.file_matches, |
|
1117 | self.file_matches, | |
1108 | self.magic_matches, |
|
1118 | self.magic_matches, | |
1109 | self.dict_key_matches, |
|
1119 | self.dict_key_matches, | |
1110 | ] |
|
1120 | ] | |
1111 | else: |
|
1121 | else: | |
1112 |
|
|
1122 | return [ | |
1113 | self.python_matches, |
|
1123 | self.python_matches, | |
1114 | self.file_matches, |
|
1124 | self.file_matches, | |
1115 | self.magic_matches, |
|
1125 | self.magic_matches, | |
1116 | self.python_func_kw_matches, |
|
1126 | self.python_func_kw_matches, | |
1117 | self.dict_key_matches, |
|
1127 | self.dict_key_matches, | |
1118 | ] |
|
1128 | ] | |
1119 | self.magic_arg_matchers = [ |
|
|||
1120 | self.magic_config_matches, |
|
|||
1121 | self.magic_color_matches, |
|
|||
1122 | ] |
|
|||
1123 |
|
||||
1124 | # This is set externally by InteractiveShell |
|
|||
1125 | self.custom_completers = None |
|
|||
1126 |
|
1129 | |||
1127 | def all_completions(self, text): |
|
1130 | def all_completions(self, text): | |
1128 | """ |
|
1131 | """ |
@@ -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