diff --git a/pylint/checkers/classes/class_checker.py b/pylint/checkers/classes/class_checker.py index 4d6e3c911da..a92f844bda8 100644 --- a/pylint/checkers/classes/class_checker.py +++ b/pylint/checkers/classes/class_checker.py @@ -684,7 +684,7 @@ def _has_same_layout_slots( "Used when a value in __slots__ conflicts with a class variable, property or method.", ), "E0243": ( - "Invalid __class__ object", + "Invalid assignement to '__class__'. Should be a class definition but got a '%s'", "invalid-class-object", "Used when an invalid object is assigned to a __class__ property. " "Only a class is permitted.", @@ -1579,7 +1579,12 @@ def _check_invalid_class_object(self, node: nodes.AssignAttr) -> None: ): # If is uninferable, we allow it to prevent false positives return - self.add_message("invalid-class-object", node=node, confidence=INFERENCE) + self.add_message( + "invalid-class-object", + node=node, + args=inferred.__class__.__name__, + confidence=INFERENCE, + ) def _check_in_slots(self, node: nodes.AssignAttr) -> None: """Check that the given AssignAttr node diff --git a/tests/functional/i/invalid/invalid_class_object.txt b/tests/functional/i/invalid/invalid_class_object.txt index 3638965647c..cf638cec389 100644 --- a/tests/functional/i/invalid/invalid_class_object.txt +++ b/tests/functional/i/invalid/invalid_class_object.txt @@ -1,5 +1,5 @@ -invalid-class-object:20:0:20:11::Invalid __class__ object:INFERENCE -invalid-class-object:21:0:21:11::Invalid __class__ object:INFERENCE -invalid-class-object:50:8:50:22:Pylint7429Good.class_defining_function_bad:Invalid __class__ object:INFERENCE -invalid-class-object:58:15:58:29:Pylint7429Good.class_defining_function_bad_inverted:Invalid __class__ object:INFERENCE -invalid-class-object:62:15:62:29:Pylint7429Good.class_defining_function_complex_bad:Invalid __class__ object:INFERENCE +invalid-class-object:20:0:20:11::Invalid assignement to '__class__'. Should be a class definition but got a 'Instance':INFERENCE +invalid-class-object:21:0:21:11::Invalid assignement to '__class__'. Should be a class definition but got a 'Const':INFERENCE +invalid-class-object:50:8:50:22:Pylint7429Good.class_defining_function_bad:Invalid assignement to '__class__'. Should be a class definition but got a 'Const':INFERENCE +invalid-class-object:58:15:58:29:Pylint7429Good.class_defining_function_bad_inverted:Invalid assignement to '__class__'. Should be a class definition but got a 'Const':INFERENCE +invalid-class-object:62:15:62:29:Pylint7429Good.class_defining_function_complex_bad:Invalid assignement to '__class__'. Should be a class definition but got a 'Const':INFERENCE