Skip to content

Commit

Permalink
Fixed a regression that caused an Unknown to appear in a type evalu…
Browse files Browse the repository at this point in the history
…ation when using nested constructor calls. This addresses #5947.
  • Loading branch information
msfterictraut committed Sep 19, 2023
1 parent 415882d commit 18bd810
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/pyright-internal/src/analyzer/constructors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
buildTypeVarContextFromSpecializedClass,
convertToInstance,
doForEachSubtype,
ensureFunctionSignaturesAreUnique,
getTypeVarScopeId,
isPartlyUnknown,
isTupleClass,
Expand Down Expand Up @@ -366,6 +367,14 @@ function validateNewMethod(
let argumentErrors = false;
const overloadsUsedForCall: FunctionType[] = [];

if (inferenceContext?.signatureTracker) {
newMethodTypeResult.type = ensureFunctionSignaturesAreUnique(
newMethodTypeResult.type,
inferenceContext.signatureTracker,
errorNode.start
);
}

const typeVarContext = new TypeVarContext(getTypeVarScopeId(type));
typeVarContext.addSolveForScope(getTypeVarScopeId(newMethodTypeResult.type));
if (type.typeAliasInfo) {
Expand Down Expand Up @@ -434,6 +443,14 @@ function validateInitMethod(
let argumentErrors = false;
const overloadsUsedForCall: FunctionType[] = [];

if (inferenceContext?.signatureTracker) {
initMethodType = ensureFunctionSignaturesAreUnique(
initMethodType,
inferenceContext.signatureTracker,
errorNode.start
);
}

// If there is an expected type, analyze the __init__ call for each of the
// subtypes that comprise the expected type. If one or more analyzes with no
// errors, use those results. This requires special-case processing because
Expand Down
6 changes: 5 additions & 1 deletion packages/pyright-internal/src/tests/samples/constructor28.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# pyright: strict

from __future__ import annotations
from typing import Any, Callable, Generic, TypeVar, overload
from typing import Any, Callable, Generic, Iterable, TypeVar, overload

T = TypeVar("T")
S = TypeVar("S", covariant=True)
Expand Down Expand Up @@ -76,3 +76,7 @@ def __call__(self, obj: Any) -> Any:


func3(ClassD(""), ClassD(""))


def func4(a: Iterable[tuple[str, ...]]):
zip(a, zip(*a))

0 comments on commit 18bd810

Please sign in to comment.