Skip to content

Commit 0daff2d

Browse files
committedApr 28, 2025
modified class_checker.py file
1 parent 2dc2550 commit 0daff2d

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed
 

‎pylint/checkers/classes/class_checker.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,15 +1535,14 @@ def _check_invalid_overridden_method(
15351535
)
15361536
return
15371537

1538-
# If both return types are not None, compare them to check for compatibility
1539-
if inferred_return.name != inferred_parent_return.name:
1540-
# The return types are incompatible, so add an error message
1538+
# Both have types but they differ - invalid
1539+
if inferred_return and inferred_parent_return and inferred_return.name != inferred_parent_return.name:
15411540
self.add_message(
15421541
"invalid-overridden-method",
15431542
args=(
15441543
function_node.name,
1545-
inferred_parent_return, # Parent return type
1546-
inferred_return # Current return type
1544+
inferred_parent_return,
1545+
inferred_return
15471546
),
15481547
node=function_node,
15491548
)
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
************* Module functional.r.invalid_overridden_method
2-
invalid_overridden_method.py:17:4: W0236: Method 'method' was expected to be <ClassDef.int l.0 at 0x794d71667490>, found it instead as <ClassDef.str l.0 at 0x794d713ce250> (invalid-overridden-method)
3-
invalid_overridden_method.py:30:4: W0236: Method 'method' was expected to be <Const.NoneType l.24 at 0x794d711b7010>, found it instead as <ClassDef.int l.0 at 0x794d71667490> (invalid-overridden-method)
4-
invalid_overridden_method.py:44:4: W0236: Method 'read_file' was expected to be <ClassDef.TextIOWrapper l.0 at 0x794d70fa4b90>, found it instead as <ClassDef.BytesIO l.0 at 0x794d71102ad0> (invalid-overridden-method)
5-
invalid_overridden_method.py:70:4: W0236: Method 'get_contents' was expected to be <Const.str l.64 at 0x794d711beb90>, found it instead as <ClassDef.dict l.0 at 0x794d715b12d0> (invalid-overridden-method)
6-
invalid_overridden_method.py:84:4: W0236: Method 'get_value' was expected to be <ClassDef.float l.0 at 0x794d71603990>, found it instead as <ClassDef.str l.0 at 0x794d713ce250> (invalid-overridden-method)
2+
invalid_overridden_method.py:17:4: W0236: Method 'method' was expected to be <ClassDef.int l.0 at 0x72df35d1f350>, found it instead as <ClassDef.str l.0 at 0x72df35c8a350> (invalid-overridden-method)
3+
invalid_overridden_method.py:30:4: W0236: Method 'method' was expected to be <Const.NoneType l.24 at 0x72df35a7b010>, found it instead as <ClassDef.int l.0 at 0x72df35d1f350> (invalid-overridden-method)
4+
invalid_overridden_method.py:44:4: W0236: Method 'read_file' was expected to be <ClassDef.TextIOWrapper l.0 at 0x72df35870dd0>, found it instead as <ClassDef.BytesIO l.0 at 0x72df359cadd0> (invalid-overridden-method)
5+
invalid_overridden_method.py:70:4: W0236: Method 'get_contents' was expected to be <Const.str l.64 at 0x72df35a82c10>, found it instead as <ClassDef.dict l.0 at 0x72df35e65110> (invalid-overridden-method)
6+
invalid_overridden_method.py:84:4: W0236: Method 'get_value' was expected to be <ClassDef.float l.0 at 0x72df35eb7850>, found it instead as <ClassDef.str l.0 at 0x72df35c8a350> (invalid-overridden-method)

0 commit comments

Comments
 (0)