Skip to content

Commit

Permalink
BUG: fix usability bugs in lookfor
Browse files Browse the repository at this point in the history
- allow numbers in function signature

- print the items in relevance order (not reverse relevance)

- include ufunc docstrings
  • Loading branch information
pv committed Jul 28, 2010
1 parent 88bcac2 commit 94f73b1
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions numpy/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re

from numpy.core.numerictypes import issubclass_, issubsctype, issubdtype
from numpy.core import product, ndarray
from numpy.core import product, ndarray, ufunc

__all__ = ['issubclass_', 'get_numpy_include', 'issubsctype', 'issubdtype',
'deprecate', 'deprecate_with_doc', 'get_numarray_include',
Expand Down Expand Up @@ -695,7 +695,7 @@ def interp(x, xp, fp, left=None, right=None):
_lookfor_caches = {}

# regexp whose match indicates that the string may contain a function signature
_function_signature_re = re.compile(r"[a-z_]+\(.*[,=].*\)", re.I)
_function_signature_re = re.compile(r"[a-z0-9_]+\(.*[,=].*\)", re.I)

def lookfor(what, module=None, import_modules=True, regenerate=False,
output=None):
Expand Down Expand Up @@ -797,7 +797,7 @@ def relevance_value(a):
# Pretty-print
s = "Search results for '%s'" % (' '.join(whats))
help_text = [s, "-"*len(s)]
for name in found:
for name in found[::-1]:
doc, kind, ix = cache[name]

doclines = [line.strip() for line in doc.strip().split("\n")
Expand Down Expand Up @@ -931,18 +931,19 @@ def _lookfor_generate_cache(module, import_modules, regenerate):
item_name = "%s.%s" % (mod_name, item_name)

if not item_name.startswith(name + '.'):
# don't crawl foreign objects
continue
# don't crawl "foreign" objects
if isinstance(v, ufunc):
# ... unless they are ufuncs
pass
else:
continue
elif not (inspect.ismodule(v) or _all is None or n in _all):
continue
stack.append(("%s.%s" % (name, n), v))
elif inspect.isclass(item):
kind = "class"
for n, v in _getmembers(item):
stack.append(("%s.%s" % (name, n), v))
# FIXME later: workaround python3.1 capsule callable bug
# by using old version of callable.
# elif callable(item):
elif hasattr(item, "__call__"):
kind = "func"

Expand Down

0 comments on commit 94f73b1

Please sign in to comment.