Skip to content

Commit

Permalink
Fixed type narrowing bug that affected the A is B type narrowing pa…
Browse files Browse the repository at this point in the history
…ttern when `A` has the type `type`. This addresses #5714.
  • Loading branch information
msfterictraut committed Aug 15, 2023
1 parent 682961d commit 97e432a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/pyright-internal/src/analyzer/typeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,10 @@ function narrowTypeForClassComparison(
}

if (isClassInstance(concreteSubtype) && TypeBase.isInstance(subtype)) {
if (ClassType.isBuiltIn(concreteSubtype, 'type')) {
return classType;
}

return undefined;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ def func5(x: type[A] | type[B] | type[T]) -> type[A] | type[B] | type[T]:
reveal_type(x, expected_text="type[B] | type[T@func5]")

return x


def func6(x: type):
if x is str:
reveal_type(x, expected_text="type[str]")
else:
reveal_type(x, expected_text="type")

0 comments on commit 97e432a

Please sign in to comment.