Skip to content

Commit

Permalink
Fixed bug that results in spurious type evaluation error when an oper…
Browse files Browse the repository at this point in the history
…ator overload method like `__add__` is implemented with a descriptor object. This addresses #9574.
  • Loading branch information
erictraut committed Dec 15, 2024
1 parent 630bb58 commit d2816bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2412,11 +2412,12 @@ export function createTypeEvaluator(
classType: ClassType,
memberName: string,
selfType?: ClassType | TypeVarType | undefined,
errorNode?: ExpressionNode | undefined,
diag?: DiagnosticAddendum,
recursionCount = 0
): FunctionType | OverloadedType | undefined {
const boundMethodResult = getTypeOfBoundMember(
/* errorNode */ undefined,
errorNode,
classType,
memberName,
/* usage */ undefined,
Expand Down Expand Up @@ -2444,6 +2445,7 @@ export function createTypeEvaluator(
boundMethodResult.type,
'__call__',
/* selfType */ undefined,
errorNode,
diag,
recursionCount
);
Expand Down Expand Up @@ -13469,7 +13471,7 @@ export function createTypeEvaluator(
const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);

if (isClass(concreteSubtype)) {
magicMethodType = getBoundMagicMethod(concreteSubtype, methodName, subtype, diag);
magicMethodType = getBoundMagicMethod(concreteSubtype, methodName, subtype, errorNode, diag);
}

if (magicMethodType) {
Expand Down Expand Up @@ -24738,6 +24740,7 @@ export function createTypeEvaluator(
concreteSrcType,
'__call__',
/* selfType */ undefined,
/* errorNode */ undefined,
/* diag */ undefined,
recursionCount
);
Expand Down Expand Up @@ -25667,6 +25670,7 @@ export function createTypeEvaluator(
objType,
'__call__',
/* selfType */ undefined,
/* errorNode */ undefined,
/* diag */ undefined,
recursionCount
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ export interface TypeEvaluator {
classType: ClassType,
memberName: string,
selfType?: ClassType | TypeVarType | undefined,
errorNode?: ExpressionNode | undefined,
diag?: DiagnosticAddendum,
recursionCount?: number
) => FunctionType | OverloadedType | undefined;
Expand Down

0 comments on commit d2816bf

Please sign in to comment.