Skip to content

Extend W0236 checker to detect return type mismatches in overridden methods #10449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
Try to increase test coverage
  • Loading branch information
Julfried committed Jul 2, 2025
commit a76ccc57536245b2af61bc78ea8c7b24a7003e4a
10 changes: 9 additions & 1 deletion tests/functional/i/invalid/invalid_overridden_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,21 @@ def bar2(self): # [invalid-overridden-method]

# https://github.com/pylint-dev/pylint/issues/10351
# Test case for return type mismatch
class ReturnType(TextIOWrapper):
pass

class BaseClass(abc.ABC):
@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):
class ChildClass1(BaseClass):
def read_file(self, path: str) -> BytesIO: # [invalid-overridden-method]
"""Implementation returns BytesIO instead of TextIOWrapper."""
return BytesIO(b"content")

class ChildClass2(BaseClass):
def read_file(self, path: str) -> ReturnType:
"""Implementation returns BytesIO instead of TextIOWrapper."""
return ReturnType(BytesIO(b"content"))
2 changes: 1 addition & 1 deletion tests/functional/i/invalid/invalid_overridden_method.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ invalid-overridden-method:46:4:46:16:InvalidDerived.method_a:Method 'method_a' w
invalid-overridden-method:49:4:49:22:InvalidDerived.method_b:Method 'method_b' was expected to be 'non-async', found it instead as 'async':UNDEFINED
invalid-overridden-method:123:4:123:11:B.bar:Method 'bar' was expected to be 'property', found it instead as 'method':UNDEFINED
invalid-overridden-method:127:4:127:12:B.bar2:Method 'bar2' was expected to be 'property', found it instead as 'method':UNDEFINED
invalid-overridden-method:140:4:140:17:ChildClass.read_file:Method 'read_file' was expected to be "return type 'TextIOWrapper'", found it instead as "return type 'BytesIO'":UNDEFINED
invalid-overridden-method:143:4:143:17:ChildClass1.read_file:Method 'read_file' was expected to be "return type 'TextIOWrapper'", found it instead as "return type 'BytesIO'":UNDEFINED
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy