How to use the parso.python.tree.Name function in parso

To help you get started, we’ve selected a few parso examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github davidhalter / jedi / test / test_parso_integration / test_parser_utils.py View on Github external
def test_call_type(self):
        call = self.get_call('hello')
        assert isinstance(call, tree.Name)
github davidhalter / parso / test / test_parser_tree.py View on Github external
def test_name(self, node, expected):
        if node.type != 'lambdef':
            assert isinstance(node.name, tree.Name)
            assert node.name.value == expected['name']
github DonJayamanne / pythonVSCode / pythonFiles / jedi / evaluate / arguments.py View on Github external
def get_calling_nodes(self):
        from jedi.evaluate.dynamic import DynamicExecutedParams
        old_arguments_list = []
        arguments = self

        while arguments not in old_arguments_list:
            if not isinstance(arguments, TreeArguments):
                break

            old_arguments_list.append(arguments)
            for name, default, star_count in reversed(list(arguments.as_tree_tuple_objects())):
                if not star_count or not isinstance(name, tree.Name):
                    continue

                names = self._evaluator.goto(arguments.context, name)
                if len(names) != 1:
                    break
                if not isinstance(names[0], ParamName):
                    break
                param = names[0].get_param()
                if isinstance(param, DynamicExecutedParams):
                    # For dynamic searches we don't even want to see errors.
                    return []
                if not isinstance(param, ExecutedParam):
                    break
                if param.var_args is None:
                    break
                arguments = param.var_args
github srusskih / SublimeJEDI / dependencies / jedi / inference / finder.py View on Github external
def filter_name(filters, name_or_str):
    """
    Searches names that are defined in a scope (the different
    ``filters``), until a name fits.
    """
    string_name = name_or_str.value if isinstance(name_or_str, Name) else name_or_str
    names = []
    for filter in filters:
        names = filter.get(string_name)
        if names:
            break

    return list(_remove_del_stmt(names))
github boxed / mutmut / mutmut / __init__.py View on Github external
def handle_assignment(children):
        mutation_index = -1  # we mutate the last value to handle multiple assignement
        if getattr(children[mutation_index], 'value', '---') != 'None':
            x = ' None'
        else:
            x = ' ""'
        children = children[:]
        children[mutation_index] = Name(value=x, start_pos=children[mutation_index].start_pos)

        return children
github getgauge / gauge-python / getgauge / parser_parso.py View on Github external
def _create_param_node(self, parent, name, prefix, is_last):
        start_pos = parent[-1].end_pos[0], parent[-1].end_pos[1] + len(prefix)
        children = [parso.python.tree.Name(name, start_pos, prefix)]
        if not is_last:
            children.append(parso.python.tree.Operator(
                ',', children[-1].end_pos))
        return parso.python.tree.Param(children, parent)
github sixty-north / cosmic-ray / src / cosmic_ray / operators / exception_replacer.py View on Github external
def _name_nodes(node):
        if isinstance(node.children[1], Name):
            return (node.children[1], )

        atom = node.children[1]
        test_list = atom.children[1]
        return test_list.children[::2]
github davidhalter / jedi / jedi / inference / finder.py View on Github external
def filter_name(filters, name_or_str):
    """
    Searches names that are defined in a scope (the different
    ``filters``), until a name fits.
    """
    string_name = name_or_str.value if isinstance(name_or_str, Name) else name_or_str
    names = []
    for filter in filters:
        names = filter.get(string_name)
        if names:
            break

    return list(names)
github srusskih / SublimeJEDI / dependencies / jedi / inference / context.py View on Github external
def py__getattribute__(self, name_or_str, name_context=None, position=None,
                           analysis_errors=True):
        """
        :param position: Position of the last statement -> tuple of line, column
        """
        if name_context is None:
            name_context = self
        names = self.goto(name_or_str, position)

        string_name = name_or_str.value if isinstance(name_or_str, Name) else name_or_str

        # This paragraph is currently needed for proper branch type inference
        # (static analysis).
        found_predefined_types = None
        if self.predefined_names and isinstance(name_or_str, Name):
            node = name_or_str
            while node is not None and not parser_utils.is_scope(node):
                node = node.parent
                if node.type in ("if_stmt", "for_stmt", "comp_for", 'sync_comp_for'):
                    try:
                        name_dict = self.predefined_names[node]
                        types = name_dict[string_name]
                    except KeyError:
                        continue
                    else:
                        found_predefined_types = types
github davidhalter / jedi / jedi / inference / context.py View on Github external
def goto(self, name_or_str, position):
        from jedi.inference import finder
        filters = _get_global_filters_for_name(
            self, name_or_str if isinstance(name_or_str, Name) else None, position,
        )
        names = finder.filter_name(filters, name_or_str)
        debug.dbg('context.goto %s in (%s): %s', name_or_str, self, names)
        return names