Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5393,6 +5393,8 @@ def check_except_handler_test(self, n: Expression, is_star: bool) -> Type:
if isinstance(ttype, AnyType):
all_types.append(ttype)
continue
if isinstance(ttype, UninhabitedType):
continue

if isinstance(ttype, FunctionLike):
item = ttype.items[0]
Expand Down
31 changes: 30 additions & 1 deletion test-data/unit/check-statements.test
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ def error_in_variadic(exc: Tuple[int, ...]) -> None:
[builtins fixtures/tuple.pyi]

[case testExceptWithMultipleTypes5]
from typing import Tuple, Type, Union
from typing import Tuple, Type, Union, Never

class E1(BaseException): pass
class E2(BaseException): pass
Expand Down Expand Up @@ -849,7 +849,36 @@ def error_in_tuple_union(exc: Tuple[Union[Type[E1], Type[E2]], Union[Type[E3], i
pass
except exc as e: # E: Exception type must be derived from BaseException (or be a tuple of exception classes)
pass
[builtins fixtures/tuple.pyi]

[case testExceptWithMultipleTypes6_no_parallel]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please open an issue in ast_serialize tracker about this, and leave a comment above why this is skipped?

from typing import Never

def random() -> bool: ...

def error_in_empty_tuple() -> None:
try:
pass
except () as e: # E: Need type annotation for "e"
pass

def error_in_empty_tuple_annotated(exc: tuple[()]) -> None:
try:
pass
except exc as e: # E: Need type annotation for "e"
pass

def error_in_conditional_empty_tuple() -> None:
try:
pass
except (BaseException if random() else ()) as e:
pass

def error_in_never(exc: Never) -> None:
try:
pass
except exc as e: # E: Need type annotation for "e"
pass
[builtins fixtures/tuple.pyi]

[case testExceptWithAnyTypes]
Expand Down
Loading