Show More
@@ -336,7 +336,6 b' class Completer(Configurable):' | |||
|
336 | 336 | #io.rprint('Completer->attr_matches, txt=%r' % text) # dbg |
|
337 | 337 | # Another option, seems to work great. Catches things like ''.<tab> |
|
338 | 338 | m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text) |
|
339 | ||
|
340 | 339 | if m: |
|
341 | 340 | expr, attr = m.group(1, 3) |
|
342 | 341 | elif self.greedy: |
@@ -346,7 +345,7 b' class Completer(Configurable):' | |||
|
346 | 345 | expr, attr = m2.group(1,2) |
|
347 | 346 | else: |
|
348 | 347 | return [] |
|
349 | ||
|
348 | ||
|
350 | 349 | try: |
|
351 | 350 | obj = eval(expr, self.namespace) |
|
352 | 351 | except: |
@@ -355,7 +354,10 b' class Completer(Configurable):' | |||
|
355 | 354 | except: |
|
356 | 355 | return [] |
|
357 | 356 | |
|
358 | words = dir2(obj) | |
|
357 | if self.limit_to__all__ and hasattr(obj, '__all__'): | |
|
358 | words = get__all__entries(obj) | |
|
359 | else: | |
|
360 | words = dir2(obj) | |
|
359 | 361 | |
|
360 | 362 | try: |
|
361 | 363 | words = generics.complete_object(obj, words) |
@@ -371,6 +373,16 b' class Completer(Configurable):' | |||
|
371 | 373 | return res |
|
372 | 374 | |
|
373 | 375 | |
|
376 | def get__all__entries(obj): | |
|
377 | """returns the strings in the __all__ attribute""" | |
|
378 | try: | |
|
379 | words = getattr(obj,'__all__') | |
|
380 | except: | |
|
381 | return [] | |
|
382 | ||
|
383 | return [w for w in words if isinstance(w, basestring)] | |
|
384 | ||
|
385 | ||
|
374 | 386 | class IPCompleter(Completer): |
|
375 | 387 | """Extension of the completer class with IPython-specific features""" |
|
376 | 388 | |
@@ -403,6 +415,16 b' class IPCompleter(Completer):' | |||
|
403 | 415 | When 0: nothing will be excluded. |
|
404 | 416 | """ |
|
405 | 417 | ) |
|
418 | limit_to__all__ = Enum((0,1), default_value=1, config=True, | |
|
419 | help="""Instruct the completer to use __all__ for the completion | |
|
420 | ||
|
421 | Specifically, when completing on ``object.<tab>``. | |
|
422 | ||
|
423 | When 1: only those names in obj.__all__ will be included. | |
|
424 | ||
|
425 | When 0 [default]: the values in the __all__ attribute are ignored | |
|
426 | """ | |
|
427 | ) | |
|
406 | 428 | |
|
407 | 429 | def __init__(self, shell=None, namespace=None, global_namespace=None, |
|
408 | 430 | alias_table=None, use_readline=True, |
@@ -602,7 +624,7 b' class IPCompleter(Completer):' | |||
|
602 | 624 | |
|
603 | 625 | def python_matches(self,text): |
|
604 | 626 | """Match attributes or global python names""" |
|
605 | ||
|
627 | ||
|
606 | 628 | #io.rprint('Completer->python_matches, txt=%r' % text) # dbg |
|
607 | 629 | if "." in text: |
|
608 | 630 | try: |
@@ -18,6 +18,7 b' from IPython.core import completer' | |||
|
18 | 18 | from IPython.external.decorators import knownfailureif |
|
19 | 19 | from IPython.utils.tempdir import TemporaryDirectory |
|
20 | 20 | from IPython.utils.generics import complete_object |
|
21 | from IPython.testing.globalipapp import get_ipython | |
|
21 | 22 | |
|
22 | 23 | #----------------------------------------------------------------------------- |
|
23 | 24 | # Test functions |
@@ -229,4 +230,15 b' def test_omit__names():' | |||
|
229 | 230 | nt.assert_false('ip.__str__' in matches) |
|
230 | 231 | nt.assert_false('ip._hidden_attr' in matches) |
|
231 | 232 | del ip._hidden_attr |
|
232 | No newline at end of file | |
|
233 | ||
|
234 | def test_get__all__entries_ok(): | |
|
235 | class A(object): | |
|
236 | __all__ = ['x', 1] | |
|
237 | words = completer.get__all__entries(A()) | |
|
238 | nt.assert_equal(words, ['x']) | |
|
239 | ||
|
240 | def test_get__all__entries_no__all__ok(): | |
|
241 | class A(object): | |
|
242 | pass | |
|
243 | words = completer.get__all__entries(A()) | |
|
244 | nt.assert_equal(words, []) No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now