Fixed bug that caused incorrect error to be reported when a recursive type alias was used in certain circumstances.

This commit is contained in:
Eric Traut 2020-10-16 08:01:50 -07:00
parent eec8b410a8
commit 8bd8679192
3 changed files with 23 additions and 2 deletions

View File

@ -614,7 +614,7 @@ export function partiallySpecializeType(type: Type, contextClassType: ClassType)
// used as type arguments in other types) with their concrete form.
export function makeTypeVarsConcrete(type: Type): Type {
return doForSubtypes(type, (subtype) => {
if (isTypeVar(subtype)) {
if (isTypeVar(subtype) && !subtype.details.recursiveTypeAliasName) {
if (subtype.details.boundType) {
return subtype.details.boundType;
}

View File

@ -0,0 +1,15 @@
# This sample tests a recursive type alias used within
# a recursive function.
from typing import Dict, Union
A = Union[str, Dict[str, "A"]]
def foo(x: A):
if isinstance(x, str):
print(x)
else:
for _, v in x.items():
foo(v)

View File

@ -1023,7 +1023,13 @@ test('TypeAlias8', () => {
test('TypeAlias9', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['typeAlias9.py']);
TestUtils.validateResults(analysisResults, 0, 0, 4);
TestUtils.validateResults(analysisResults, 0);
});
test('TypeAlias10', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['typeAlias10.py']);
TestUtils.validateResults(analysisResults, 0);
});
test('Dictionary1', () => {