Exemplo n.º 1
0
 def visit_subscript(self, node: astroid.Subscript) -> None:
     if node.ctx == astroid.Load:
         node.inf_type = self._handle_call(node, '__getitem__',
                                           node.value.inf_type.getValue(),
                                           node.slice.inf_type.getValue())
     elif node.ctx == astroid.Store:
         node.inf_type = TypeInfo(
             NoType)  # type assigned when parent Assign node is visited
     elif node.ctx == astroid.Del:
         node.inf_type = self._handle_call(node, '__delitem__',
                                           node.value.inf_type.getValue(),
                                           node.slice.inf_type.getValue())
Exemplo n.º 2
0
    def _fix_end(node: astroid.Subscript) -> astroid.Subscript:
        if isinstance(node.slice, astroid.Slice):
            # In this case, the subscript node already contains the final ].
            return node

        # Search the remaining source code for the "]" char.
        if _get_last_child(node):
            set_from_last_child(node)
            line_i = node.end_lineno - 1  # convert 1 to 0 index.
            char_i = node.end_col_offset
        else:
            line_i = node.value.end_lineno - 1  # convert 1 to 0 index.
            char_i = node.value.end_col_offset

        while char_i < len(
                source_code[line_i]) and source_code[line_i][char_i] != ']':
            if char_i == len(source_code[line_i]
                             ) - 1 or source_code[line_i][char_i] == '#':
                char_i = 0
                line_i += 1
            else:
                char_i += 1

        node.end_lineno, node.end_col_offset = line_i + 1, char_i + 1
        return node
    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)
Exemplo n.º 4
0
    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)