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