Skip to content

Commit

Permalink
[invalid-class-object] Better error message giving more information
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Sep 16, 2022
1 parent 67eeec0 commit 8831477
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 7 additions & 2 deletions pylint/checkers/classes/class_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tests/functional/i/invalid/invalid_class_object.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8831477

Please sign in to comment.