def names(source=None, path=None, encoding='utf-8', all_scopes=False, definitions=True, references=False): """ Returns a list of `Definition` objects, containing name parts. This means you can call ``Definition.goto_assignments()`` and get the reference of a name. The parameters are the same as in :py:class:`Script`, except or the following ones: :param all_scopes: If True lists the names of all scopes instead of only the module namespace. :param definitions: If True lists the names that have been defined by a class, function or a statement (``a = b`` returns ``a``). :param references: If True lists all the names that are not listed by ``definitions=True``. E.g. ``a = b`` returns ``b``. """ def def_ref_filter(_def): is_def = _def.is_definition() return definitions and is_def or references and not is_def # Set line/column to a random position, because they don't matter. script = Script(source, line=1, column=0, path=path, encoding=encoding) defs = [classes.Definition(script._evaluator, name_part) for name_part in get_module_names(script._parser.module(), all_scopes)] return sorted(filter(def_ref_filter, defs), key=lambda x: (x.line, x.column))
def names(source=None, path=None, encoding='utf-8', all_scopes=False, definitions=True, references=False): """ Returns a list of `Definition` objects, containing name parts. This means you can call ``Definition.goto_assignments()`` and get the reference of a name. The parameters are the same as in :py:class:`Script`, except or the following ones: :param all_scopes: If True lists the names of all scopes instead of only the module namespace. :param definitions: If True lists the names that have been defined by a class, function or a statement (``a = b`` returns ``a``). :param references: If True lists all the names that are not listed by ``definitions=True``. E.g. ``a = b`` returns ``b``. """ def def_ref_filter(_def): is_def = _def.is_definition() return definitions and is_def or references and not is_def # Set line/column to a random position, because they don't matter. script = Script(source, line=1, column=0, path=path, encoding=encoding) defs = [classes.Definition(script._evaluator, name_part) for name_part in get_module_names(script._get_module(), all_scopes)] return sorted(filter(def_ref_filter, defs), key=lambda x: (x.line, x.column))
def get_definitions(script): def def_ref_filter(_def): is_def = _def.is_definition() return is_def defs = [jedi.api.classes.Definition(script._evaluator, name_part) for name_part in get_module_names(script._parser.module(), False)] return sorted(filter(def_ref_filter, defs), key=lambda x: (x.line, x.column))
def names(source=None, path=None, encoding='utf-8', all_scopes=False, definitions=True, references=False, environment=None): """ Returns a list of `Definition` objects, containing name parts. This means you can call ``Definition.goto_assignments()`` and get the reference of a name. The parameters are the same as in :py:class:`Script`, except or the following ones: :param all_scopes: If True lists the names of all scopes instead of only the module namespace. :param definitions: If True lists the names that have been defined by a class, function or a statement (``a = b`` returns ``a``). :param references: If True lists all the names that are not listed by ``definitions=True``. E.g. ``a = b`` returns ``b``. """ def def_ref_filter(_def): is_def = _def._name.tree_name.is_definition() return definitions and is_def or references and not is_def def create_name(name): if name.parent.type == 'param': cls = ParamName else: cls = TreeNameDefinition is_module = name.parent.type == 'file_input' return cls( module_context.create_context(name if is_module else name.parent), name ) # Set line/column to a random position, because they don't matter. script = Script(source, line=1, column=0, path=path, encoding=encoding, environment=environment) module_context = script._get_module() defs = [ classes.Definition( script._evaluator, create_name(name) ) for name in get_module_names(script._module_node, all_scopes) ] return sorted(filter(def_ref_filter, defs), key=lambda x: (x.line, x.column))