예제 #1
0
파일: __init__.py 프로젝트: wimmerX/jedi
    def _names(self, all_scopes=False, definitions=True, references=False):
        def def_ref_filter(_def):
            is_def = _def._name.tree_name.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.
        module_context = self._get_module_context()
        defs = [
            classes.Definition(self._inference_state,
                               module_context.create_name(name))
            for name in get_module_names(self._module_node, all_scopes)
        ]
        return sorted(filter(def_ref_filter, defs),
                      key=lambda x: (x.line, x.column))
예제 #2
0
파일: __init__.py 프로젝트: steff456/jedi
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

    # 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_context()
    defs = [
        classes.Definition(script._inference_state,
                           module_context.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))