Mixin For Extra Tab Completions

The ExtraTabCompletion class helps you to extend the tab completions for objects. This is used in interfaces with third-party interpreters where we want, for example, gap.[TAB] to also list GAP commands and not only the Python methods of the gap interface. To use it, just inherit (usually by multiple inheritance) from ExtraTabCompletion and implement a _tab_completion method that returns a list of strings. These strings are then included in the tab completions on instances. It is up to you to make these “fake” method names work, usually by implementing __getattr__.

EXAMPLES:

sage: from sage.interfaces.tab_completion import ExtraTabCompletion
sage: class Foo(ExtraTabCompletion, object):
....:      def a(self):
....:          return 1
....:      def _tab_completion(self):
....:          return ['c', 'd']
sage: f = Foo()
sage: f.b = 2
sage: sorted(dir(f))
[..., '_tab_completion', 'a', 'b', 'c', 'd']
>>> from sage.all import *
>>> from sage.interfaces.tab_completion import ExtraTabCompletion
>>> class Foo(ExtraTabCompletion, object):
...      def a(self):
...          return Integer(1)
...      def _tab_completion(self):
...          return ['c', 'd']
>>> f = Foo()
>>> f.b = Integer(2)
>>> sorted(dir(f))
[..., '_tab_completion', 'a', 'b', 'c', 'd']
from sage.interfaces.tab_completion import ExtraTabCompletion
class Foo(ExtraTabCompletion, object):
     def a(self):
         return 1
     def _tab_completion(self):
         return ['c', 'd']
f = Foo()
f.b = 2
sorted(dir(f))
class sage.interfaces.tab_completion.ExtraTabCompletion[source]

Bases: object

sage.interfaces.tab_completion.completions(s, globs)[source]

Return a list of completions in the given context.

INPUT:

  • s – string

  • globs – string: object dictionary; context in which to search for completions, e.g., globals()

OUTPUT: list of strings

EXAMPLES:

sage: X.<x> = PolynomialRing(QQ)
sage: import sage.interfaces.tab_completion as s
sage: p = x**2 + 1
sage: s.completions('p.co',globals()) # indirect doctest
['p.coefficient',...]

sage: s.completions('dic',globals()) # indirect doctest
['dickman_rho', 'dict']
>>> from sage.all import *
>>> X = PolynomialRing(QQ, names=('x',)); (x,) = X._first_ngens(1)
>>> import sage.interfaces.tab_completion as s
>>> p = x**Integer(2) + Integer(1)
>>> s.completions('p.co',globals()) # indirect doctest
['p.coefficient',...]

>>> s.completions('dic',globals()) # indirect doctest
['dickman_rho', 'dict']
X.<x> = PolynomialRing(QQ)
import sage.interfaces.tab_completion as s
p = x**2 + 1
s.completions('p.co',globals()) # indirect doctest
s.completions('dic',globals()) # indirect doctest