From 86715ec758db1e1dbebd000fa28d4423cd8ab2da Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Tue, 18 Jun 2024 23:31:13 +0200 Subject: [PATCH] Fixed bug that results in unions consisting of different specialized forms of a generic TypedDict to "lose" all but one of these subtypes. This addresses #8169. --- packages/pyright-internal/src/analyzer/types.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/pyright-internal/src/analyzer/types.ts b/packages/pyright-internal/src/analyzer/types.ts index ef2d7074a..924b2302b 100644 --- a/packages/pyright-internal/src/analyzer/types.ts +++ b/packages/pyright-internal/src/analyzer/types.ts @@ -3498,11 +3498,14 @@ function _addTypeIfUnique(unionType: UnionType, typeToAdd: UnionableType) { // If the typeToAdd is a TypedDict that is the same class as the // existing type, see if one of them is a proper subset of the other. if (ClassType.isTypedDictClass(type) && ClassType.isSameGenericClass(type, typeToAdd)) { - if (ClassType.isTypedDictNarrower(typeToAdd, type)) { - return; - } else if (ClassType.isTypedDictNarrower(type, typeToAdd)) { - unionType.subtypes[i] = typeToAdd; - return; + // Do not proceed if the TypedDicts are generic and have different type arguments. + if (!type.typeArguments && !typeToAdd.typeArguments) { + if (ClassType.isTypedDictNarrower(typeToAdd, type)) { + return; + } else if (ClassType.isTypedDictNarrower(type, typeToAdd)) { + unionType.subtypes[i] = typeToAdd; + return; + } } } }