Open
Description
Bug description
I recently stumbled across this in a project. The invalid-overridden-method (W0236) checker doesn't detect return type mismatches in overridden methods. Tools like Pyright/Pylance correctly detect this issue, but Pylint misses it.
Here is an example code snippet:
from abc import ABC, abstractmethod
from io import TextIOWrapper, BytesIO
class BaseClass(ABC):
@abstractmethod
def read_file(self, path: str) -> TextIOWrapper:
"""Abstract method that should return a TextIOWrapper."""
raise NotImplementedError("Method must be implemented by subclass")
class ChildClass(BaseClass):
def read_file(self, path: str) -> BytesIO: # Should trigger invalid-overridden-method
"""Implementation returns BytesIO instead of TextIOWrapper."""
return BytesIO(b"content")
Command used
pylint my_module.py
Pylint output
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 0.00/10, +10.00)
Expected behavior
Pylint should report an invalid-overridden-method (W0236) error since the return type BytesIO is not compatible with the parent method's return type TextIOWrapper.
Pyright correctly reports: "Method 'read_file' overrides class 'BaseClass' in an incompatible manner. Return type mismatch: base method returns type 'TextIOWrapper', override returns type 'BytesIO'."
Pylint version
pylint 4.0.0-dev0
astroid 4.0.0a0
Python 3.13.2 (main, Mar 17 2025, 21:04:07) [MSC v.1943 64 bit (AMD64)]