##// END OF EJS Templates
cache regexp and PEP8
Piti Ongmongkolkul -
Show More
@@ -497,6 +497,12 b' class IPCompleter(Completer):'
497 else:
497 else:
498 self.clean_glob = self._clean_glob
498 self.clean_glob = self._clean_glob
499
499
500 #regexp to parse docstring for function signature
501 self.docstring_sig_re = re.compile(r'^[\w|\s.]+\(([^)]*)\).*')
502 self.docstring_kwd_re = re.compile(r'[\s|\[]*(\w+)(?:\s*=\s*.*)')
503 #use this if positional argument name is also needed
504 #= re.compile(r'[\s|\[]*(\w+)(?:\s*=?\s*.*)')
505
500 # All active matcher routines for completion
506 # All active matcher routines for completion
501 self.matchers = [self.python_matches,
507 self.matchers = [self.python_matches,
502 self.file_matches,
508 self.file_matches,
@@ -670,24 +676,23 b' class IPCompleter(Completer):'
670 form 'min(iterable[, key=func])\n' to find
676 form 'min(iterable[, key=func])\n' to find
671 keyword argument names.
677 keyword argument names.
672 """
678 """
673 if doc is None: return []
679 if doc is None:
674 doc = doc.lstrip()
680 return []
675 sio = StringIO.StringIO(doc)
681 sio = StringIO.StringIO(doc.lstrip())
676 #care only the firstline
682 #care only the firstline
677 #docstring can be long
683 #docstring can be long
678 line = sio.readline()
684 line = sio.readline()
679 p = re.compile(r'^[\w|\s.]+\(([^)]*)\).*')
685 #p = re.compile(r'^[\w|\s.]+\(([^)]*)\).*')
680 #'min(iterable[, key=func])\n' -> 'iterable[, key=func]'
686 #'min(iterable[, key=func])\n' -> 'iterable[, key=func]'
681 sig = p.search(line)
687 sig = self.docstring_sig_re.search(line)
682 if sig is None: return []
688 if sig is None:
689 return []
683 # iterable[, key=func]' -> ['iterable[' ,' key=func]']
690 # iterable[, key=func]' -> ['iterable[' ,' key=func]']
684 sig = sig.groups()[0].split(',')
691 sig = sig.groups()[0].split(',')
685 #use this if you want iterable to show up too
686 #q = re.compile('[\s|\[]*(\w+)(?:\s*=?\s*.*)')
687 q = re.compile('[\s|\[]*(\w+)(?:\s*=\s*.*)')
688 ret = []
692 ret = []
689 for s in sig:
693 for s in sig:
690 ret += q.findall(s)
694 #re.compile(r'[\s|\[]*(\w+)(?:\s*=\s*.*)')
695 ret += self.docstring_kwd_re.findall(s)
691 return ret
696 return ret
692
697
693 def _default_arguments(self, obj):
698 def _default_arguments(self, obj):
@@ -702,16 +707,16 b' class IPCompleter(Completer):'
702 #for cython embededsignature=True the constructor docstring
707 #for cython embededsignature=True the constructor docstring
703 #belongs to the object itself not __init__
708 #belongs to the object itself not __init__
704 ret += self._default_arguments_from_docstring(
709 ret += self._default_arguments_from_docstring(
705 getattr(obj,'__doc__',''))
710 getattr(obj, '__doc__', ''))
706 # for classes, check for __init__,__new__
711 # for classes, check for __init__,__new__
707 call_obj = (getattr(obj,'__init__',None) or
712 call_obj = (getattr(obj, '__init__', None) or
708 getattr(obj,'__new__',None))
713 getattr(obj, '__new__', None))
709 # for all others, check if they are __call__able
714 # for all others, check if they are __call__able
710 elif hasattr(obj, '__call__'):
715 elif hasattr(obj, '__call__'):
711 call_obj = obj.__call__
716 call_obj = obj.__call__
712
717
713 ret += self._default_arguments_from_docstring(
718 ret += self._default_arguments_from_docstring(
714 getattr(call_obj,'__doc__',''))
719 getattr(call_obj, '__doc__', ''))
715
720
716 try:
721 try:
717 args,_,_1,defaults = inspect.getargspec(call_obj)
722 args,_,_1,defaults = inspect.getargspec(call_obj)
General Comments 0
You need to be logged in to leave comments. Login now