|
4 | 4 | import sys |
5 | 5 | import warnings |
6 | 6 | from collections.abc import Sequence |
7 | | -from typing import Any, Callable, Final, Literal, Optional, TypeVar, Union, cast, overload |
| 7 | +from typing import Any, Callable, Final, Literal, TypeVar, Union, cast, overload |
8 | 8 |
|
9 | 9 | from mypy import defaults, errorcodes as codes, message_registry |
10 | 10 | from mypy.errors import Errors |
@@ -714,7 +714,7 @@ def fix_function_overloads(self, stmts: list[Statement]) -> list[Statement]: |
714 | 714 | current_overload.extend(if_block_with_overload.body[-1].items) |
715 | 715 | else: |
716 | 716 | current_overload.append( |
717 | | - cast(Union[Decorator, FuncDef], if_block_with_overload.body[0]) |
| 717 | + cast(Decorator | FuncDef, if_block_with_overload.body[0]) |
718 | 718 | ) |
719 | 719 | else: |
720 | 720 | if last_if_stmt is not None: |
@@ -760,7 +760,7 @@ def fix_function_overloads(self, stmts: list[Statement]) -> list[Statement]: |
760 | 760 | cast(list[IfStmt], if_block_with_overload.body[:-1]) |
761 | 761 | ) |
762 | 762 | last_if_overload = cast( |
763 | | - Union[Decorator, FuncDef, OverloadedFuncDef], |
| 763 | + Decorator | FuncDef | OverloadedFuncDef, |
764 | 764 | if_block_with_overload.body[-1], |
765 | 765 | ) |
766 | 766 | last_if_unknown_truth_value = if_unknown_truth_value |
@@ -806,9 +806,7 @@ def _check_ifstmt_for_overloads( |
806 | 806 | ): |
807 | 807 | return None |
808 | 808 |
|
809 | | - overload_name = cast( |
810 | | - Union[Decorator, FuncDef, OverloadedFuncDef], stmt.body[0].body[-1] |
811 | | - ).name |
| 809 | + overload_name = cast(Decorator | FuncDef | OverloadedFuncDef, stmt.body[0].body[-1]).name |
812 | 810 | if stmt.else_body is None: |
813 | 811 | return overload_name |
814 | 812 |
|
@@ -991,7 +989,7 @@ def do_func_def( |
991 | 989 | self.errors, line=lineno, override_column=n.col_offset |
992 | 990 | ).translate_expr_list(func_type_ast.argtypes) |
993 | 991 | # Use a cast to work around `list` invariance |
994 | | - arg_types = cast(list[Optional[Type]], translated_args) |
| 992 | + arg_types = cast(list[Type | None], translated_args) |
995 | 993 | return_type = TypeConverter(self.errors, line=lineno).visit(func_type_ast.returns) |
996 | 994 |
|
997 | 995 | # add implicit self type |
@@ -1646,7 +1644,7 @@ def visit_Call(self, n: Call) -> CallExpr: |
1646 | 1644 | self.visit(n.func), |
1647 | 1645 | arg_types, |
1648 | 1646 | arg_kinds, |
1649 | | - cast("list[Optional[str]]", [None] * len(args)) + keyword_names, |
| 1647 | + cast("list[str | None]", [None] * len(args)) + keyword_names, |
1650 | 1648 | ) |
1651 | 1649 | return self.set_line(e, n) |
1652 | 1650 |
|
|
0 commit comments