示例#1
0
    def _called_thru_default_qs(self, node):
        """Checks if an attribute is being accessed throught the default
        queryset manager, ie: MyClass.objects.filter(some='value')"""
        last_child = node.last_child()
        if not last_child:
            return False

        # the default qs manager is called 'objects', we check for it here
        attrname = getattr(last_child, 'attrname', None)
        if attrname != 'objects':
            return False

        base_cls = last_child.last_child()
        base_classes = DOCUMENT_BASES
        for cls in base_cls.inferred():
            if node_is_subclass(cls, *base_classes):
                return True

        return False
示例#2
0
    def visit_call(self, node):

        children = node.get_children()

        attr = next(children)
        meth = safe_infer(attr)
        if meth:
            return False

        last_child = attr.last_child()

        if last_child is None:
            return False

        attr_self = safe_infer(last_child)
        cls = getattr(attr_self, '_proxied', None)

        if node_is_subclass(
                cls, *
                DOCUMENT_BASES) and not name_is_from_model(attr.attrname):
            self.add_message('no-member',
                             node=attr,
                             args=('Document', cls.name, attr.attrname, ''))
示例#3
0
def test_node_is_subclass_false():
    module = astroid.parse(test_cls)
    cls = module.body[0]
    r = utils.node_is_subclass(cls, *DOCUMENT_BASES)
    assert r is False
示例#4
0
def test_node_is_subclass_bad_node():
    module = astroid.parse(test_funcdef)
    funcdef = module.body[0]
    r = utils.node_is_subclass(funcdef, *DOCUMENT_BASES)
    assert r is False
示例#5
0
def test_node_is_subclass_true():
    module = astroid.parse(test_doc)
    cls = module.body[2]
    r = utils.node_is_subclass(cls, *DOCUMENT_BASES)
    assert r is True