From 71a9b2c22762382bcdff89f6bdfba744976529c5 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Fri, 3 Nov 2023 09:57:15 -0700 Subject: [PATCH] Fixed bug that causes a false positive MRO error when creating a subclass of a generic TypedDict and another TypedDict. This addresses #6318. --- packages/pyright-internal/src/analyzer/typeUtils.ts | 6 +++--- .../src/tests/samples/typedDict18.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/pyright-internal/src/analyzer/typeUtils.ts b/packages/pyright-internal/src/analyzer/typeUtils.ts index 3a4ef3d6c924..2e1829c6f6dd 100644 --- a/packages/pyright-internal/src/analyzer/typeUtils.ts +++ b/packages/pyright-internal/src/analyzer/typeUtils.ts @@ -3006,9 +3006,9 @@ export function computeMroLinearization(classType: ClassType): boolean { // Generic has some special-case logic (see description of __mro_entries__ // in PEP 560) that we need to account for here. if (ClassType.isBuiltIn(baseClass, 'Generic')) { - // If the class is a Protocol, the generic is ignored for the purposes - // of computing the MRO. - if (ClassType.isProtocolClass(classType)) { + // If the class is a Protocol or TypedDict, the generic is ignored for + // the purposes of computing the MRO. + if (ClassType.isProtocolClass(classType) || ClassType.isTypedDictClass(classType)) { return false; } diff --git a/packages/pyright-internal/src/tests/samples/typedDict18.py b/packages/pyright-internal/src/tests/samples/typedDict18.py index 021170f20902..6cb48852eaa6 100644 --- a/packages/pyright-internal/src/tests/samples/typedDict18.py +++ b/packages/pyright-internal/src/tests/samples/typedDict18.py @@ -126,3 +126,15 @@ def __init__(self, **attrs: Unpack[TD9[_T1]]) -> None: f7 = ClassA(x=1) reveal_type(f7, expected_text="ClassA[int]") + + +class TD10(TypedDict, Generic[_T1]): + x: _T1 + + +class TD11(TypedDict): + y: int + + +class TD12(TD10[str], TD11): + ...