Show More
@@ -85,7 +85,7 b' from IPython.utils import generics' | |||
|
85 | 85 | from IPython.utils import io |
|
86 | 86 | from IPython.utils.dir2 import dir2 |
|
87 | 87 | from IPython.utils.process import arg_split |
|
88 | from IPython.utils.traitlets import CBool | |
|
88 | from IPython.utils.traitlets import CBool, Enum | |
|
89 | 89 | |
|
90 | 90 | #----------------------------------------------------------------------------- |
|
91 | 91 | # Globals |
@@ -276,8 +276,9 b' class Completer(Configurable):' | |||
|
276 | 276 | but can be unsafe because the code is actually evaluated on TAB. |
|
277 | 277 | """ |
|
278 | 278 | ) |
|
279 | ||
|
279 | 280 | |
|
280 | def __init__(self, namespace=None, global_namespace=None, config=None): | |
|
281 | def __init__(self, namespace=None, global_namespace=None, config=None, **kwargs): | |
|
281 | 282 | """Create a new completer for the command line. |
|
282 | 283 | |
|
283 | 284 | Completer(namespace=ns,global_namespace=ns2) -> completer instance. |
@@ -311,7 +312,7 b' class Completer(Configurable):' | |||
|
311 | 312 | else: |
|
312 | 313 | self.global_namespace = global_namespace |
|
313 | 314 | |
|
314 | super(Completer, self).__init__(config=config) | |
|
315 | super(Completer, self).__init__(config=config, **kwargs) | |
|
315 | 316 | |
|
316 | 317 | def complete(self, text, state): |
|
317 | 318 | """Return the next possible completion for 'text'. |
@@ -417,10 +418,30 b' class IPCompleter(Completer):' | |||
|
417 | 418 | |
|
418 | 419 | if self.readline: |
|
419 | 420 | self.readline.set_completer_delims(self.splitter.get_delims()) |
|
421 | ||
|
422 | merge_completions = CBool(True, config=True, | |
|
423 | help="""Whether to merge completion results into a single list | |
|
424 | ||
|
425 | If False, only the completion results from the first non-empty | |
|
426 | completer will be returned. | |
|
427 | """ | |
|
428 | ) | |
|
429 | omit__names = Enum((0,1,2), default_value=2, config=True, | |
|
430 | help="""Instruct the completer to omit private method names | |
|
431 | ||
|
432 | Specifically, when completing on ``object.<tab>``. | |
|
433 | ||
|
434 | When 2 [default]: all names that start with '_' will be excluded. | |
|
435 | ||
|
436 | When 1: all 'magic' names (``__foo__``) will be excluded. | |
|
437 | ||
|
438 | When 0: nothing will be excluded. | |
|
439 | """ | |
|
440 | ) | |
|
420 | 441 | |
|
421 | 442 | def __init__(self, shell=None, namespace=None, global_namespace=None, |
|
422 |
|
|
|
423 | config=None): | |
|
443 | alias_table=None, use_readline=True, | |
|
444 | config=None, **kwargs): | |
|
424 | 445 | """IPCompleter() -> completer |
|
425 | 446 | |
|
426 | 447 | Return a completer object suitable for use by the readline library |
@@ -438,10 +459,6 b' class IPCompleter(Completer):' | |||
|
438 | 459 | handle cases (such as IPython embedded inside functions) where |
|
439 | 460 | both Python scopes are visible. |
|
440 | 461 | |
|
441 | - The optional omit__names parameter sets the completer to omit the | |
|
442 | 'magic' names (__magicname__) for python objects unless the text | |
|
443 | to be completed explicitly starts with one or more underscores. | |
|
444 | ||
|
445 | 462 | - If alias_table is supplied, it should be a dictionary of aliases |
|
446 | 463 | to complete. |
|
447 | 464 | |
@@ -463,12 +480,10 b' class IPCompleter(Completer):' | |||
|
463 | 480 | |
|
464 | 481 | # _greedy_changed() depends on splitter and readline being defined: |
|
465 | 482 | Completer.__init__(self, namespace=namespace, global_namespace=global_namespace, |
|
466 | config=config) | |
|
483 | config=config, **kwargs) | |
|
467 | 484 | |
|
468 | 485 | # List where completion matches will be stored |
|
469 | 486 | self.matches = [] |
|
470 | self.omit__names = omit__names | |
|
471 | self.merge_completions = shell.readline_merge_completions | |
|
472 | 487 | self.shell = shell.shell |
|
473 | 488 | if alias_table is None: |
|
474 | 489 | alias_table = {} |
@@ -322,8 +322,6 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||
|
322 | 322 | # The readline stuff will eventually be moved to the terminal subclass |
|
323 | 323 | # but for now, we can't do that as readline is welded in everywhere. |
|
324 | 324 | readline_use = CBool(True, config=True) |
|
325 | readline_merge_completions = CBool(True, config=True) | |
|
326 | readline_omit__names = Enum((0,1,2), default_value=2, config=True) | |
|
327 | 325 | readline_remove_delims = Unicode('-/~', config=True) |
|
328 | 326 | # don't use \M- bindings by default, because they |
|
329 | 327 | # conflict with 8-bit encodings. See gh-58,gh-88 |
@@ -1856,7 +1854,6 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||
|
1856 | 1854 | self.Completer = IPCompleter(shell=self, |
|
1857 | 1855 | namespace=self.user_ns, |
|
1858 | 1856 | global_namespace=self.user_global_ns, |
|
1859 | omit__names=self.readline_omit__names, | |
|
1860 | 1857 | alias_table=self.alias_manager.alias_table, |
|
1861 | 1858 | use_readline=self.has_readline, |
|
1862 | 1859 | config=self.config, |
@@ -3657,6 +3657,19 b' Defaulting color scheme to \'NoColor\'"""' | |||
|
3657 | 3657 | In [2]: %config IPCompleter |
|
3658 | 3658 | IPCompleter options |
|
3659 | 3659 | ----------------- |
|
3660 | IPCompleter.omit__names=<Enum> | |
|
3661 | Current: 2 | |
|
3662 | Choices: (0, 1, 2) | |
|
3663 | Instruct the completer to omit private method names | |
|
3664 | Specifically, when completing on ``object.<tab>``. | |
|
3665 | When 2 [default]: all names that start with '_' will be excluded. | |
|
3666 | When 1: all 'magic' names (``__foo__``) will be excluded. | |
|
3667 | When 0: nothing will be excluded. | |
|
3668 | IPCompleter.merge_completions=<CBool> | |
|
3669 | Current: True | |
|
3670 | Whether to merge completion results into a single list | |
|
3671 | If False, only the completion results from the first non-empty completer | |
|
3672 | will be returned. | |
|
3660 | 3673 | IPCompleter.greedy=<CBool> |
|
3661 | 3674 | Current: False |
|
3662 | 3675 | Activate greedy completion |
@@ -13,6 +13,7 b' import unittest' | |||
|
13 | 13 | import nose.tools as nt |
|
14 | 14 | |
|
15 | 15 | # our own packages |
|
16 | from IPython.config.loader import Config | |
|
16 | 17 | from IPython.core import completer |
|
17 | 18 | from IPython.external.decorators import knownfailureif |
|
18 | 19 | from IPython.utils.tempdir import TemporaryDirectory |
@@ -205,3 +206,27 b' def test_greedy_completions():' | |||
|
205 | 206 | _,c = ip.complete('.',line='a[0].') |
|
206 | 207 | nt.assert_true('a[0].real' in c, "Should have completed on a[0]: %s"%c) |
|
207 | 208 | |
|
209 | def test_omit__names(): | |
|
210 | # also happens to test IPCompleter as a configurable | |
|
211 | ip = get_ipython() | |
|
212 | ip._hidden_attr = 1 | |
|
213 | c = ip.Completer | |
|
214 | ip.ex('ip=get_ipython()') | |
|
215 | cfg = Config() | |
|
216 | cfg.IPCompleter.omit__names = 0 | |
|
217 | c.update_config(cfg) | |
|
218 | s,matches = c.complete('ip.') | |
|
219 | nt.assert_true('ip.__str__' in matches) | |
|
220 | nt.assert_true('ip._hidden_attr' in matches) | |
|
221 | cfg.IPCompleter.omit__names = 1 | |
|
222 | c.update_config(cfg) | |
|
223 | s,matches = c.complete('ip.') | |
|
224 | nt.assert_false('ip.__str__' in matches) | |
|
225 | nt.assert_true('ip._hidden_attr' in matches) | |
|
226 | cfg.IPCompleter.omit__names = 2 | |
|
227 | c.update_config(cfg) | |
|
228 | s,matches = c.complete('ip.') | |
|
229 | nt.assert_false('ip.__str__' in matches) | |
|
230 | nt.assert_false('ip._hidden_attr' in matches) | |
|
231 | del ip._hidden_attr | |
|
232 | No newline at end of file |
@@ -35,7 +35,7 b' from IPython.config.loader import (' | |||
|
35 | 35 | from IPython.config.application import boolean_flag, catch_config_error |
|
36 | 36 | from IPython.core import release |
|
37 | 37 | from IPython.core import usage |
|
38 | from IPython.core.completer import Completer | |
|
38 | from IPython.core.completer import IPCompleter | |
|
39 | 39 | from IPython.core.crashhandler import CrashHandler |
|
40 | 40 | from IPython.core.formatters import PlainTextFormatter |
|
41 | 41 | from IPython.core.application import ( |
@@ -199,7 +199,7 b' class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):' | |||
|
199 | 199 | TerminalInteractiveShell, |
|
200 | 200 | ProfileDir, |
|
201 | 201 | PlainTextFormatter, |
|
202 | Completer, | |
|
202 | IPCompleter, | |
|
203 | 203 | ] |
|
204 | 204 | |
|
205 | 205 | subcommands = Dict(dict( |
General Comments 0
You need to be logged in to leave comments.
Login now