grub.pycode¶
Searching python code
-
class
grub.pycode.PyCodeSearcherBase(search_store: Union[str, Mapping, module] = <grub.base.DfltSearchStore object>, tfidf: sklearn.feature_extraction.text.TfidfVectorizer = TfidfVectorizer(token_pattern=re.compile('\n # Find words in a string. Order matters!\n [A-Z]+(?=[A-Z][a-z]) | # All upper case before a capitalized word\n [A-Z]?[a-z]+ | # Capitalized words / all lower case\n [A-Z]+ | # All u, re.VERBOSE)), knn: sklearn.neighbors._unsupervised.NearestNeighbors = NearestNeighbors(metric='cosine', n_neighbors=10))[source]¶
-
grub.pycode.ddir(obj)[source]¶ List of (dir(obj)) attributes of obj that don’t start with an underscore :param obj: Any python object :return: A list of attribute names
-
grub.pycode.func_semantic_info(func) → dict[source]¶ A dict of semantically relevant infos about a function.
-
grub.pycode.non_doctest_lines(doc)[source]¶ Generator of lines of the doc string that are not in a doctest scope.
>>> def _test_func(): ... '''Line 1 ... Another ... >>> doctest_1 ... >>> doctest_2 ... line_after_a_doc_test ... another_line_that_is_in_the_doc_test scope ... ... But now we're out of a doctest's scope ... ... >>> Oh no, another doctest! ... ''' >>> from inspect import getdoc >>> >>> list(non_doctest_lines(getdoc(_test_func))) ['Line 1', 'Another', "But now we're out of a doctest's scope", '']
- Parameters
doc –
- Returns
-
grub.pycode.search_documented_attributes(obj, obj_to_attrs=<function ddir>, max_results=10)[source]¶ Search the documented attributes of a python object :param obj: Any python object :param obj_to_attrs: The function that gives you attribute names of an object. :return: A SearchStore instance to search attributes via their docs
>>> from inspect import getmodule >>> containing_module = getmodule(search_documented_attributes) # the module of this function >>> search_module = search_documented_attributes(containing_module, max_results=3) >>> list(search_module('documented attributes')) # if you get an error here, it's probably just be that the docs changed ['search_documented_attributes', 'ddir', 'inspect'] >>> list(search_module('documented objects')) # if you get an error here, it's probably just be that the docs changed ['search_documented_attributes', 'DocTestFinder', 'doctest_finder']