mirror of
https://github.com/microsoft/pyright.git
synced 2024-10-06 12:57:14 +03:00
Fixed recent regression that results in a false positive error under certain circumstances when yield expression includes a call to a constructor. This addresses #8552. (#8553)
This commit is contained in:
parent
28b452ac0f
commit
a1f24db683
@ -14268,13 +14268,15 @@ export function createTypeEvaluator(
|
||||
if (enclosingFunction) {
|
||||
const functionTypeInfo = getTypeOfFunction(enclosingFunction);
|
||||
if (functionTypeInfo) {
|
||||
const returnType = FunctionType.getEffectiveReturnType(functionTypeInfo.functionType);
|
||||
let returnType = FunctionType.getEffectiveReturnType(functionTypeInfo.functionType);
|
||||
if (returnType) {
|
||||
const liveScopeIds = ParseTreeUtils.getTypeVarScopesForNode(node);
|
||||
returnType = updateTypeWithInternalTypeVars(returnType, liveScopeIds);
|
||||
|
||||
expectedYieldType = getGeneratorYieldType(returnType, !!enclosingFunction.d.isAsync);
|
||||
|
||||
const generatorTypeArgs = getGeneratorTypeArgs(returnType);
|
||||
if (generatorTypeArgs && generatorTypeArgs.length >= 2) {
|
||||
const liveScopeIds = ParseTreeUtils.getTypeVarScopesForNode(node);
|
||||
sentType = updateTypeWithInternalTypeVars(generatorTypeArgs[1], liveScopeIds);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,20 @@
|
||||
# This sample tests various type checking operations relating to
|
||||
# generator functions (those with a "yield" method).
|
||||
|
||||
from typing import Any, Awaitable, Generator, Iterable, Iterator, Protocol, TypedDict
|
||||
from typing import (
|
||||
Any,
|
||||
Awaitable,
|
||||
Generator,
|
||||
Generic,
|
||||
Iterable,
|
||||
Iterator,
|
||||
NamedTuple,
|
||||
Protocol,
|
||||
TypedDict,
|
||||
TypeVar,
|
||||
)
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
class ClassA:
|
||||
@ -21,6 +34,18 @@ class ClassC:
|
||||
pass
|
||||
|
||||
|
||||
class NT1(NamedTuple, Generic[T]):
|
||||
value: T
|
||||
|
||||
|
||||
class ClassD(Generic[T]):
|
||||
def __init__(self, obj: T) -> None:
|
||||
self.obj = obj
|
||||
|
||||
def ingest(self) -> Generator[NT1[T], None, None]:
|
||||
yield NT1(self.obj)
|
||||
|
||||
|
||||
def generator1() -> Generator[ClassA, ClassB, ClassC]:
|
||||
cont = ClassB()
|
||||
while cont.shouldContinue():
|
||||
|
Loading…
Reference in New Issue
Block a user