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
Add a test case for this
  • Loading branch information
Julfried committed May 26, 2025
commit 72bb0a8ddfb9ccfad250b6075dda29faf5ea2015
14 changes: 14 additions & 0 deletions tests/functional/i/invalid/invalid_overridden_method.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pylint: disable=missing-docstring,too-few-public-methods,disallowed-name,invalid-name,unused-argument
import abc
from io import TextIOWrapper, BytesIO


class SuperClass(metaclass=abc.ABCMeta):
Expand Down Expand Up @@ -125,3 +126,16 @@ def bar(self): # [invalid-overridden-method]
@multiple_returns
def bar2(self): # [invalid-overridden-method]
return False


# Test case for return type mismatch from the issue
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):
def read_file(self, path: str) -> BytesIO: # [invalid-overridden-method]
"""Implementation returns BytesIO instead of TextIOWrapper."""
return BytesIO(b"content")
13 changes: 7 additions & 6 deletions tests/functional/i/invalid/invalid_overridden_method.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
invalid-overridden-method:38:4:38:12:InvalidDerived.prop:Method 'prop' was expected to be 'property', found it instead as 'method':UNDEFINED
invalid-overridden-method:41:4:41:20:InvalidDerived.async_method:Method 'async_method' was expected to be 'async', found it instead as 'non-async':UNDEFINED
invalid-overridden-method:45:4:45:16:InvalidDerived.method_a:Method 'method_a' was expected to be 'method', found it instead as 'property':UNDEFINED
invalid-overridden-method:48:4:48:22:InvalidDerived.method_b:Method 'method_b' was expected to be 'non-async', found it instead as 'async':UNDEFINED
invalid-overridden-method:122:4:122:11:B.bar:Method 'bar' was expected to be 'property', found it instead as 'method':UNDEFINED
invalid-overridden-method:126:4:126:12:B.bar2:Method 'bar2' was expected to be 'property', found it instead as 'method':UNDEFINED
invalid-overridden-method:39:4:39:12:InvalidDerived.prop:Method 'prop' was expected to be 'property', found it instead as 'method':UNDEFINED
invalid-overridden-method:42:4:42:20:InvalidDerived.async_method:Method 'async_method' was expected to be 'async', found it instead as 'non-async':UNDEFINED
invalid-overridden-method:46:4:46:16:InvalidDerived.method_a:Method 'method_a' was expected to be 'method', found it instead as 'property':UNDEFINED
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:139:4:139:17:ChildClass.read_file:Method 'read_file' was expected to be "return type 'TextIOWrapper'", found it instead as "return type 'BytesIO'":UNDEFINED
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