pylint/checkers/variables.py
def _check_self_cls_assign(self, node):
        """Check that self/cls don't get assigned"""
        assign_names = {
            target.name
            for target in node.targets
            if isinstance(target, astroid.AssignName)
        }
        scope = node.scope()
        nonlocals_with_same_name = any(
            child
            for child in scope.body
            if isinstance(child, astroid.Nonlocal) and assign_names & set(child.names)
        )
        if nonlocals_with_same_name:
            scope = node.scope().parent.scope()

        if not (
            isinstance(scope, astroid.scoped_nodes.FunctionDef)
            and scope.is_method()
            and "builtins.staticmethod" not in scope.decoratornames()
        ):
            return
        argument_names = scope.argnames()
        if not argument_names:
            return
        self_cls_name = argument_names[0]
        target_assign_names = (
            target.name
            for target in node.targets
            if isinstance(target, astroid.node_classes.AssignName)
        )
        if self_cls_name in target_assign_names:
            self.add_message("self-cls-assignment", node=node, args=(self_cls_name))
def _check_self_cls_assign(self, node):
        """Check that self/cls don't get assigned"""
        assign_names = {
            target.name
            for target in node.targets
            if isinstance(target, astroid.AssignName)
        }
        scope = node.scope()
        nonlocals_with_same_name = any(
            child
            for child in scope.body
            if isinstance(child, astroid.Nonlocal) and assign_names & set(child.names)
        )
        if nonlocals_with_same_name:
            scope = node.scope().parent.scope()

        if not (
            isinstance(scope, astroid.scoped_nodes.FunctionDef)
            and scope.is_method()
            and "builtins.staticmethod" not in scope.decoratornames()
        ):
            return
        argument_names = scope.argnames()
        if not argument_names:
            return
        self_cls_name = argument_names[0]
        target_assign_names = (
            target.name
            for target in node.targets
            if isinstance(target, astroid.node_classes.AssignName)
        )
        if self_cls_name in target_assign_names:
            self.add_message("self-cls-assignment", node=node, args=(self_cls_name))
def _check_self_cls_assign ( self , node ) : assign_names = { target . name for target in node . targets if isinstance ( target , astroid . AssignName ) } scope = node . scope ( ) nonlocals_with_same_name = any ( child for child in scope . body if isinstance ( child , astroid . Nonlocal ) and assign_names & set ( child . names ) ) if nonlocals_with_same_name : scope = node . scope ( ) . parent . scope ( ) if not ( isinstance ( scope , astroid . scoped_nodes . FunctionDef ) and scope . is_method ( ) and "builtins.staticmethod" not in scope . decoratornames ( ) ) : return argument_names = scope . argnames ( ) if not argument_names : return self_cls_name = argument_names [ 0 ] target_assign_names = ( target . name for target in node . targets if isinstance ( target , astroid . node_classes . AssignName ) ) if self_cls_name in target_assign_names : self . add_message ( "self-cls-assignment" , node = node , args = ( self_cls_name ) )
Check that self/cls don't get assigned
Check that self / cls don t get assigned