Exemplo n.º 1
0
    def visit_subscript(self, node):
        supported_protocol = None
        if isinstance(node.value, (astroid.ListComp, astroid.DictComp)):
            return

        if node.ctx == astroid.Load:
            supported_protocol = supports_getitem
            msg = 'unsubscriptable-object'
        elif node.ctx == astroid.Store:
            supported_protocol = supports_setitem
            msg = 'unsupported-assignment-operation'
        elif node.ctx == astroid.Del:
            supported_protocol = supports_delitem
            msg = 'unsupported-delete-operation'

        if isinstance(node.value, astroid.SetComp):
            self.add_message(msg, args=node.value.as_string(),
                             node=node.value)
            return

        if is_inside_abstract_class(node):
            return

        inferred = safe_infer(node.value)
        if inferred is None or inferred is astroid.YES:
            return

        if not supported_protocol(inferred):
            self.add_message(msg, args=node.value.as_string(), node=node.value)
Exemplo n.º 2
0
    def visit_subscript(self, node):
        supported_protocol = None
        if isinstance(node.value, (astroid.ListComp, astroid.DictComp)):
            return

        if node.ctx == astroid.Load:
            supported_protocol = supports_getitem
            msg = "unsubscriptable-object"
        elif node.ctx == astroid.Store:
            supported_protocol = supports_setitem
            msg = "unsupported-assignment-operation"
        elif node.ctx == astroid.Del:
            supported_protocol = supports_delitem
            msg = "unsupported-delete-operation"

        if isinstance(node.value, astroid.SetComp):
            self.add_message(msg, args=node.value.as_string(), node=node.value)
            return

        if is_inside_abstract_class(node):
            return

        inferred = safe_infer(node.value)
        if inferred is None or inferred is astroid.YES:
            return

        if not supported_protocol(inferred):
            self.add_message(msg, args=node.value.as_string(), node=node.value)
Exemplo n.º 3
0
 def _check_mapping(self, node):
     if is_inside_abstract_class(node):
         return
     if isinstance(node, astroid.DictComp):
         return
     infered = safe_infer(node)
     if infered is None or infered is astroid.YES:
         return
     if not is_mapping(infered):
         self.add_message('not-a-mapping', args=node.as_string(), node=node)
Exemplo n.º 4
0
 def _check_membership_test(self, node):
     if is_inside_abstract_class(node):
         return
     if is_comprehension(node):
         return
     infered = safe_infer(node)
     if infered is None or infered is astroid.YES:
         return
     if not supports_membership_test(infered):
         self.add_message("unsupported-membership-test", args=node.as_string(), node=node)
Exemplo n.º 5
0
 def _check_mapping(self, node):
     if is_inside_abstract_class(node):
         return
     if isinstance(node, astroid.DictComp):
         return
     infered = safe_infer(node)
     if infered is None or infered is astroid.YES:
         return
     if not is_mapping(infered):
         self.add_message("not-a-mapping", args=node.as_string(), node=node)
Exemplo n.º 6
0
 def _check_iterable(self, node):
     if is_inside_abstract_class(node):
         return
     if is_comprehension(node):
         return
     infered = safe_infer(node)
     if infered is None or infered is astroid.YES:
         return
     if not is_iterable(infered):
         self.add_message("not-an-iterable", args=node.as_string(), node=node)
Exemplo n.º 7
0
 def _check_iterable(self, node):
     if is_inside_abstract_class(node):
         return
     if is_comprehension(node):
         return
     infered = safe_infer(node)
     if infered is None or infered is astroid.YES:
         return
     if not is_iterable(infered):
         self.add_message('not-an-iterable',
                          args=node.as_string(),
                          node=node)
Exemplo n.º 8
0
 def _check_membership_test(self, node):
     if is_inside_abstract_class(node):
         return
     if is_comprehension(node):
         return
     infered = safe_infer(node)
     if infered is None or infered is astroid.YES:
         return
     if not supports_membership_test(infered):
         self.add_message('unsupported-membership-test',
                          args=node.as_string(),
                          node=node)
Exemplo n.º 9
0
    def visit_subscript(self, node):
        if isinstance(node.value, (astroid.ListComp, astroid.DictComp)):
            return
        if isinstance(node.value, astroid.SetComp):
            self.add_message('unsubscriptable-object',
                             args=node.value.as_string(),
                             node=node.value)
            return

        infered = safe_infer(node.value)
        if infered is None or infered is astroid.YES:
            return

        if is_inside_abstract_class(node):
            return

        if not supports_subscript(infered):
            self.add_message('unsubscriptable-object',
                             args=node.value.as_string(),
                             node=node.value)