当前位置: 首页>>代码示例>>Python>>正文


Python astroid.List方法代码示例

本文整理汇总了Python中astroid.List方法的典型用法代码示例。如果您正苦于以下问题:Python astroid.List方法的具体用法?Python astroid.List怎么用?Python astroid.List使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在astroid的用法示例。


在下文中一共展示了astroid.List方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _nose_tools_trivial_transform

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import List [as 别名]
def _nose_tools_trivial_transform():
    """Custom transform for the nose.tools module."""
    stub = _BUILDER.string_build('''__all__ = []''')
    all_entries = ['ok_', 'eq_']

    for pep8_name, method in _nose_tools_functions():
        all_entries.append(pep8_name)
        stub[pep8_name] = method

    # Update the __all__ variable, since nose.tools
    # does this manually with .append.
    all_assign = stub['__all__'].parent
    all_object = astroid.List(all_entries)
    all_object.parent = all_assign
    all_assign.value = all_object
    return stub 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:18,代码来源:brain_nose.py

示例2: lookup

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import List [as 别名]
def lookup(node, name):
    """Lookup the given special method name in the given *node*

    If the special method was found, then a list of attributes
    will be returned. Otherwise, `astroid.AttributeInferenceError`
    is going to be raised.
    """
    if isinstance(node, (astroid.List,
                         astroid.Tuple,
                         astroid.Const,
                         astroid.Dict,
                         astroid.Set)):
        return _builtin_lookup(node, name)
    elif isinstance(node, astroid.Instance):
        return _lookup_in_mro(node, name)
    elif isinstance(node, astroid.ClassDef):
        return _class_lookup(node, name)

    raise exceptions.AttributeInferenceError(
        attribute=name,
        target=node
    ) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:24,代码来源:dunder_lookup.py

示例3: _annotated_unpack_infer

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import List [as 别名]
def _annotated_unpack_infer(stmt, context=None):
    """
    Recursively generate nodes inferred by the given statement.
    If the inferred value is a list or a tuple, recurse on the elements.
    Returns an iterator which yields tuples in the format
    ('original node', 'infered node').
    """
    if isinstance(stmt, (astroid.List, astroid.Tuple)):
        for elt in stmt.elts:
            inferred = utils.safe_infer(elt)
            if inferred and inferred is not astroid.YES:
                yield elt, inferred
        return
    for infered in stmt.infer(context):
        if infered is astroid.YES:
            continue
        yield stmt, infered 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:19,代码来源:exceptions.py

示例4: visit_starred

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import List [as 别名]
def visit_starred(self, node):
        """Check that a Starred expression is used in an assignment target."""
        if isinstance(node.parent, astroid.Call):
            # f(*args) is converted to Call(args=[Starred]), so ignore
            # them for this check.
            return
        if PY35 and isinstance(node.parent,
                               (astroid.List, astroid.Tuple,
                                astroid.Set, astroid.Dict)):
            # PEP 448 unpacking.
            return

        stmt = node.statement()
        if not isinstance(stmt, astroid.Assign):
            return

        if stmt.value is node or stmt.value.parent_of(node):
            self.add_message('star-needs-assignment-target', node=node) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:20,代码来源:base.py

示例5: _check_literal_comparison

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import List [as 别名]
def _check_literal_comparison(self, literal, node):
        """Check if we compare to a literal, which is usually what we do not want to do."""
        nodes = (astroid.List,
                 astroid.Tuple,
                 astroid.Dict,
                 astroid.Set)
        is_other_literal = isinstance(literal, nodes)
        is_const = False
        if isinstance(literal, astroid.Const):
            if literal.value in (True, False, None):
                # Not interested in this values.
                return
            is_const = isinstance(literal.value, (bytes, str, int, float))

        if is_const or is_other_literal:
            self.add_message('literal-comparison', node=node) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:18,代码来源:base.py

示例6: _get_tuple_targets

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import List [as 别名]
def _get_tuple_targets(self, t: astroid.Tuple) -> List[type]:
        target_tvars = []
        for subtarget in t.elts:
            if isinstance(subtarget, astroid.AssignAttr):
                target_tvars.append(self._lookup_attribute_type(subtarget, subtarget.expr.inf_type, subtarget.attrname))
            elif isinstance(subtarget, astroid.Starred):
                if isinstance(subtarget.value, astroid.AssignAttr):
                    target_tvars.append(self.lookup_typevar(subtarget.value, subtarget.value.attrname))
                else:
                    target_tvars.append(self.lookup_typevar(subtarget.value, subtarget.value.name))
            elif isinstance(subtarget, astroid.Subscript):
                target_tvars.append(self._handle_call(subtarget, '__getitem__', subtarget.value.inf_type,
                                                      subtarget.slice.inf_type))
            else:
                target_tvars.append(self.lookup_typevar(subtarget, subtarget.name))
        return target_tvars 
开发者ID:pyta-uoft,项目名称:pyta,代码行数:18,代码来源:type_inference_visitor.py

示例7: numpy_function_infer_call_result

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import List [as 别名]
def numpy_function_infer_call_result(node):
    """
    A wrapper around infer_call_result method bounded to the node.

    :param node: the node which infer_call_result should be filtered
    :type node: FunctionDef
    :return: a function that filter the results of the call to node.infer_call_result
    :rtype: function
    """
    #  Put the origin infer_call_result method into the closure
    origin_infer_call_result = node.infer_call_result

    def infer_call_result_wrapper(caller=None, context=None):
        """
        Call the origin infer_call_result method bounded to the node instance and
        filter the results to remove List and Tuple instances
        """
        unfiltered_infer_call_result = origin_infer_call_result(caller, context)
        return (
            x
            for x in unfiltered_infer_call_result
            if not isinstance(x, (astroid.List, astroid.Tuple))
        )

    return infer_call_result_wrapper 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:27,代码来源:brain_numpy.py

示例8: _nose_tools_trivial_transform

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import List [as 别名]
def _nose_tools_trivial_transform():
    """Custom transform for the nose.tools module."""
    stub = _BUILDER.string_build("""__all__ = []""")
    all_entries = ["ok_", "eq_"]

    for pep8_name, method in _nose_tools_functions():
        all_entries.append(pep8_name)
        stub[pep8_name] = method

    # Update the __all__ variable, since nose.tools
    # does this manually with .append.
    all_assign = stub["__all__"].parent
    all_object = astroid.List(all_entries)
    all_object.parent = all_assign
    all_assign.value = all_object
    return stub 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:18,代码来源:brain_nose.py

示例9: lookup

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import List [as 别名]
def lookup(node, name):
    """Lookup the given special method name in the given *node*

    If the special method was found, then a list of attributes
    will be returned. Otherwise, `astroid.AttributeInferenceError`
    is going to be raised.
    """
    if isinstance(
        node, (astroid.List, astroid.Tuple, astroid.Const, astroid.Dict, astroid.Set)
    ):
        return _builtin_lookup(node, name)
    if isinstance(node, astroid.Instance):
        return _lookup_in_mro(node, name)
    if isinstance(node, astroid.ClassDef):
        return _class_lookup(node, name)

    raise exceptions.AttributeInferenceError(attribute=name, target=node) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:19,代码来源:dunder_lookup.py

示例10: _annotated_unpack_infer

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import List [as 别名]
def _annotated_unpack_infer(stmt, context=None):
    """
    Recursively generate nodes inferred by the given statement.
    If the inferred value is a list or a tuple, recurse on the elements.
    Returns an iterator which yields tuples in the format
    ('original node', 'infered node').
    """
    if isinstance(stmt, (astroid.List, astroid.Tuple)):
        for elt in stmt.elts:
            inferred = utils.safe_infer(elt)
            if inferred and inferred is not astroid.Uninferable:
                yield elt, inferred
        return
    for infered in stmt.infer(context):
        if infered is astroid.Uninferable:
            continue
        yield stmt, infered 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:19,代码来源:exceptions.py

示例11: get_exception_handlers

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import List [as 别名]
def get_exception_handlers(
    node: astroid.node_classes.NodeNG, exception=Exception
) -> List[astroid.ExceptHandler]:
    """Return the collections of handlers handling the exception in arguments.

    Args:
        node (astroid.NodeNG): A node that is potentially wrapped in a try except.
        exception (builtin.Exception or str): exception or name of the exception.

    Returns:
        list: the collection of handlers that are handling the exception or None.

    """
    context = find_try_except_wrapper_node(node)
    if isinstance(context, astroid.TryExcept):
        return [
            handler for handler in context.handlers if error_of_type(handler, exception)
        ]
    return None 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:21,代码来源:utils.py

示例12: visit_assign

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import List [as 别名]
def visit_assign(self, node):
        """Check unbalanced tuple unpacking for assignments
        and unpacking non-sequences as well as in case self/cls
        get assigned.
        """
        self._check_self_cls_assign(node)
        if not isinstance(node.targets[0], (astroid.Tuple, astroid.List)):
            return

        targets = node.targets[0].itered()
        try:
            infered = utils.safe_infer(node.value)
            if infered is not None:
                self._check_unpacking(infered, node, targets)
        except astroid.InferenceError:
            return 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:18,代码来源:variables.py

示例13: visit_starred

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import List [as 别名]
def visit_starred(self, node):
        """Check that a Starred expression is used in an assignment target."""
        if isinstance(node.parent, astroid.Call):
            # f(*args) is converted to Call(args=[Starred]), so ignore
            # them for this check.
            return
        if PY35 and isinstance(
            node.parent, (astroid.List, astroid.Tuple, astroid.Set, astroid.Dict)
        ):
            # PEP 448 unpacking.
            return

        stmt = node.statement()
        if not isinstance(stmt, astroid.Assign):
            return

        if stmt.value is node or stmt.value.parent_of(node):
            self.add_message("star-needs-assignment-target", node=node) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:20,代码来源:base.py

示例14: _check_cmp_argument

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import List [as 别名]
def _check_cmp_argument(self, node):
        # Check that the `cmp` argument is used
        kwargs = []
        if isinstance(node.func, astroid.Attribute) and node.func.attrname == "sort":
            inferred = utils.safe_infer(node.func.expr)
            if not inferred:
                return

            builtins_list = "{}.list".format(bases.BUILTINS)
            if isinstance(inferred, astroid.List) or inferred.qname() == builtins_list:
                kwargs = node.keywords

        elif isinstance(node.func, astroid.Name) and node.func.name == "sorted":
            inferred = utils.safe_infer(node.func)
            if not inferred:
                return

            builtins_sorted = "{}.sorted".format(bases.BUILTINS)
            if inferred.qname() == builtins_sorted:
                kwargs = node.keywords

        for kwarg in kwargs or []:
            if kwarg.arg == "cmp":
                self.add_message("using-cmp-argument", node=node)
                return 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:27,代码来源:python3.py

示例15: get_all_elements

# 需要导入模块: import astroid [as 别名]
# 或者: from astroid import List [as 别名]
def get_all_elements(node):
    """Recursively returns all atoms in nested lists and tuples."""
    if isinstance(node, (astroid.Tuple, astroid.List)):
        for child in node.elts:
            for e in get_all_elements(child):
                yield e
    else:
        yield node 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:10,代码来源:utils.py


注:本文中的astroid.List方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。