mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-19 04:07:36 +03:00
Fixed bug that caused incorrect error to be reported when a recursive type alias was used in certain circumstances.
This commit is contained in:
parent
eec8b410a8
commit
8bd8679192
@ -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;
|
||||
}
|
||||
|
15
packages/pyright-internal/src/tests/samples/typeAlias10.py
Normal file
15
packages/pyright-internal/src/tests/samples/typeAlias10.py
Normal 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)
|
@ -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', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user