Skip to content

Commit

Permalink
Fixed a bug that resulted in a false positive error when constructing…
Browse files Browse the repository at this point in the history
… a tuple of classes in the second argument of an `isinstance` or `issubclass` call. This addresses #5018.
  • Loading branch information
msfterictraut committed Apr 27, 2023
1 parent 2575969 commit 924bf71
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/pyright-internal/src/analyzer/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3594,6 +3594,7 @@ export class Checker extends ParseTreeWalker {

doForEachSubtype(type, (subtype) => {
subtype = this._evaluator.makeTopLevelTypeVarsConcrete(subtype);
subtype = transformPossibleRecursiveTypeAlias(subtype);

switch (subtype.category) {
case TypeCategory.Any:
Expand Down
6 changes: 5 additions & 1 deletion packages/pyright-internal/src/tests/samples/isinstance3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


from abc import abstractmethod
from typing import Any, Generic, Tuple, Type, TypeVar, Union
from typing import Any, Generic, Sequence, Tuple, Type, TypeVar, Union


_T = TypeVar("_T", int, str)
Expand Down Expand Up @@ -57,3 +57,7 @@ def execute(self, var: Union[_T, Tuple[_T]]) -> None:

if isinstance(var, self.v2):
pass


def func1(exceptions: Sequence[type[BaseException]], exception: Exception):
return isinstance(exception, tuple(exceptions))

0 comments on commit 924bf71

Please sign in to comment.