Skip to content
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

Fixed bug that leads to false positive when a method is overridden by… #9434

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27275,7 +27275,8 @@ export function createTypeEvaluator(

// Now check the return type.
const baseReturnType = getEffectiveReturnType(baseMethod);
const overrideReturnType = getEffectiveReturnType(overrideMethod);
const overrideReturnType = solveAndApplyConstraints(getEffectiveReturnType(overrideMethod), constraints);

if (
!assignType(
baseReturnType,
Expand Down
30 changes: 19 additions & 11 deletions packages/pyright-internal/src/tests/samples/methodOverride4.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,31 @@
_T3 = TypeVar("_T3")


class Base(Generic[_TSource]):
class BaseA(Generic[_TSource]):
@abstractmethod
def method1(
self, mapper: Callable[[_TSource, _T1], _TResult], other: "Base[_T1]"
) -> "Base[_TResult]":
self, mapper: Callable[[_TSource, _T1], _TResult], other: "BaseA[_T1]"
) -> "BaseA[_TResult]":
raise NotImplementedError


class Subclass1(Base[_TSource]):
class SubclassA1(BaseA[_TSource]):
def method1(
self, mapper: Callable[[_TSource, _T2], _TResult], other: Base[_T2]
) -> Base[_TResult]:
return Subclass2()
self, mapper: Callable[[_TSource, _T2], _TResult], other: BaseA[_T2]
) -> BaseA[_TResult]:
return SubclassA2()


class Subclass2(Base[_TSource]):
class SubclassA2(BaseA[_TSource]):
def method1(
self, mapper: Callable[[_TSource, _T3], _TResult], other: Base[_T3]
) -> Base[_TResult]:
return Subclass2()
self, mapper: Callable[[_TSource, _T3], _TResult], other: BaseA[_T3]
) -> BaseA[_TResult]:
return SubclassA2()


class BaseB:
def f(self, v: str) -> str: ...


class SubclassB1(BaseB):
def f[T](self, v: T) -> T: ...
Loading