Skip to content

Commit

Permalink
Fixed bug that causes a false positive MRO error when creating a subc…
Browse files Browse the repository at this point in the history
…lass of a generic TypedDict and another TypedDict. This addresses microsoft#6318.
  • Loading branch information
erictraut committed Nov 3, 2023
1 parent fb67700 commit 71a9b2c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/pyright-internal/src/analyzer/typeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 12 additions & 0 deletions packages/pyright-internal/src/tests/samples/typedDict18.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
...

0 comments on commit 71a9b2c

Please sign in to comment.