##// 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):
General Comments 0
You need to be logged in to leave comments. Login now