def defined_names(source, source_path=None, source_encoding="utf-8"): """ Get all definitions in `source` sorted by its position. This functions can be used for listing functions, classes and data defined in a file. This can be useful if you want to list them in "sidebar". Each element in the returned list also has `defined_names` method which can be used to get sub-definitions (e.g., methods in class). :rtype: list of api_classes.Definition """ parser = parsing.Parser(modules.source_to_unicode(source, source_encoding), module_path=source_path) return api_classes._defined_names(parser.scope)
def defined_names(source, path=None, source_encoding='utf-8'): """ Get all definitions in `source` sorted by its position. This functions can be used for listing functions, classes and data defined in a file. This can be useful if you want to list them in "sidebar". Each element in the returned list also has `defined_names` method which can be used to get sub-definitions (e.g., methods in class). :rtype: list of api_classes.Definition """ parser = Parser( modules.source_to_unicode(source, source_encoding), module_path=path, ) return api_classes._defined_names(parser.module)