當前位置: 首頁>>代碼示例>>Python>>正文


Python astroid.Tuple方法代碼示例

本文整理匯總了Python中astroid.Tuple方法的典型用法代碼示例。如果您正苦於以下問題:Python astroid.Tuple方法的具體用法?Python astroid.Tuple怎麽用?Python astroid.Tuple使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在astroid的用法示例。


在下文中一共展示了astroid.Tuple方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: lookup

# 需要導入模塊: import astroid [as 別名]
# 或者: from astroid import Tuple [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

示例2: _annotated_unpack_infer

# 需要導入模塊: import astroid [as 別名]
# 或者: from astroid import Tuple [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

示例3: visit_starred

# 需要導入模塊: import astroid [as 別名]
# 或者: from astroid import Tuple [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

示例4: _check_literal_comparison

# 需要導入模塊: import astroid [as 別名]
# 或者: from astroid import Tuple [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

示例5: _get_tuple_targets

# 需要導入模塊: import astroid [as 別名]
# 或者: from astroid import Tuple [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

示例6: visit_subscript

# 需要導入模塊: import astroid [as 別名]
# 或者: from astroid import Tuple [as 別名]
def visit_subscript(self, node: astroid.Subscript) -> None:
        if isinstance(node.slice.inf_type, TypeFail):
            node.inf_type = node.slice.inf_type
        elif node.ctx == astroid.Load:
            try:
                val_inf_type = self.type_constraints.resolve(node.value.inf_type)
                value_gorg = val_inf_type >> _gorg
            except AttributeError:
                value_gorg = None

            if value_gorg is type and isinstance(node.slice, astroid.Index):
                if isinstance(node.slice.value, astroid.Tuple):
                    node.inf_type = wrap_container(_node_to_type(node.value), *_node_to_type(node.slice.value))
                else:
                    node.inf_type = wrap_container(_node_to_type(node.value), _node_to_type(node.slice.value))
            else:
                node.inf_type = self._handle_call(node, '__getitem__', node.value.inf_type, node.slice.inf_type)
        elif node.ctx == astroid.Store:
            node.inf_type = NoType()
        elif node.ctx == astroid.Del:
            node.inf_type = self._handle_call(node, '__delitem__', node.value.inf_type, node.slice.inf_type)

    ##############################################################################
    # Loops
    ############################################################################## 
開發者ID:pyta-uoft,項目名稱:pyta,代碼行數:27,代碼來源:type_inference_visitor.py

示例7: _generic_to_annotation

# 需要導入模塊: import astroid [as 別名]
# 或者: from astroid import Tuple [as 別名]
def _generic_to_annotation(ann_node_type: type, node: NodeNG) -> TypeResult:
    if (isinstance(ann_node_type, _GenericAlias) and
            ann_node_type is getattr(typing, getattr(ann_node_type, '_name', '') or '', None)):
        if ann_node_type == Dict:
            ann_type = wrap_container(ann_node_type, Any, Any)
        elif ann_node_type == Tuple:
            # TODO: Add proper support for multi-parameter Tuples
            ann_type = wrap_container(ann_node_type, Any)
        else:
            ann_type = wrap_container(ann_node_type, Any)
    elif isinstance(ann_node_type, _GenericAlias):
        parsed_args = []
        for arg in ann_node_type.__args__:
            _generic_to_annotation(arg, node) >> parsed_args.append
        ann_type = wrap_container(ann_node_type, *parsed_args)
    else:
        try:
            _type_check(ann_node_type, '')
        except TypeError:
            return TypeFailAnnotationInvalid(node)
        else:
            ann_type = TypeInfo(ann_node_type)
    return ann_type 
開發者ID:pyta-uoft,項目名稱:pyta,代碼行數:25,代碼來源:base.py

示例8: numpy_function_infer_call_result

# 需要導入模塊: import astroid [as 別名]
# 或者: from astroid import Tuple [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

示例9: lookup

# 需要導入模塊: import astroid [as 別名]
# 或者: from astroid import Tuple [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 Tuple [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: clobber_in_except

# 需要導入模塊: import astroid [as 別名]
# 或者: from astroid import Tuple [as 別名]
def clobber_in_except(
    node: astroid.node_classes.NodeNG
) -> Tuple[bool, Tuple[str, str]]:
    """Checks if an assignment node in an except handler clobbers an existing
    variable.

    Returns (True, args for W0623) if assignment clobbers an existing variable,
    (False, None) otherwise.
    """
    if isinstance(node, astroid.AssignAttr):
        return True, (node.attrname, "object %r" % (node.expr.as_string(),))
    if isinstance(node, astroid.AssignName):
        name = node.name
        if is_builtin(name):
            return (True, (name, "builtins"))

        stmts = node.lookup(name)[1]
        if stmts and not isinstance(
            stmts[0].assign_type(),
            (astroid.Assign, astroid.AugAssign, astroid.ExceptHandler),
        ):
            return True, (name, "outer scope (line %s)" % stmts[0].fromlineno)
    return False, None 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:25,代碼來源:utils.py

示例12: visit_starred

# 需要導入模塊: import astroid [as 別名]
# 或者: from astroid import Tuple [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

示例13: visit_assign

# 需要導入模塊: import astroid [as 別名]
# 或者: from astroid import Tuple [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

示例14: visit_assign

# 需要導入模塊: import astroid [as 別名]
# 或者: from astroid import Tuple [as 別名]
def visit_assign(self, node):
        # we don't handle multiple assignment nor slice assignment
        target = node.targets[0]
        if isinstance(target, (astroid.Tuple, astroid.Subscript)):
            return
        # ignore NoneType
        if is_none(node):
            return
        _type = node_type(node.value)
        if _type:
            self._assigns[-1].setdefault(target.as_string(), []).append(
                (node, _type.pytype())) 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:14,代碼來源:redefined_variable_type.py

示例15: _check_catching_non_exception

# 需要導入模塊: import astroid [as 別名]
# 或者: from astroid import Tuple [as 別名]
def _check_catching_non_exception(self, handler, exc, part):
        if isinstance(exc, astroid.Tuple):
            # Check if it is a tuple of exceptions.
            inferred = [utils.safe_infer(elt) for elt in exc.elts]
            if any(node is astroid.YES for node in inferred):
                # Don't emit if we don't know every component.
                return
            if all(node and (utils.inherit_from_std_ex(node) or
                             not utils.has_known_bases(node))
                   for node in inferred):
                return

        if not isinstance(exc, astroid.ClassDef):
            # Don't emit the warning if the infered stmt
            # is None, but the exception handler is something else,
            # maybe it was redefined.
            if (isinstance(exc, astroid.Const) and
                    exc.value is None):
                if ((isinstance(handler.type, astroid.Const) and
                     handler.type.value is None) or
                        handler.type.parent_of(exc)):
                    # If the exception handler catches None or
                    # the exception component, which is None, is
                    # defined by the entire exception handler, then
                    # emit a warning.
                    self.add_message('catching-non-exception',
                                     node=handler.type,
                                     args=(part.as_string(), ))
            else:
                self.add_message('catching-non-exception',
                                 node=handler.type,
                                 args=(part.as_string(), ))
            return

        if (not utils.inherit_from_std_ex(exc) and
                exc.name not in self._builtin_exceptions):
            if utils.has_known_bases(exc):
                self.add_message('catching-non-exception',
                                 node=handler.type,
                                 args=(exc.name, )) 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:42,代碼來源:exceptions.py


注:本文中的astroid.Tuple方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。