|
32 | 32 | ) |
33 | 33 | from mypy.checkpattern import PatternChecker |
34 | 34 | from mypy.constraints import SUPERTYPE_OF |
35 | | -from mypy.erasetype import erase_type, erase_typevars, shallow_erase_type_for_equality, remove_instance_last_known_values |
| 35 | +from mypy.erasetype import ( |
| 36 | + erase_type, |
| 37 | + erase_typevars, |
| 38 | + remove_instance_last_known_values, |
| 39 | + shallow_erase_type_for_equality, |
| 40 | +) |
36 | 41 | from mypy.errorcodes import TYPE_VAR, UNUSED_AWAITABLE, UNUSED_COROUTINE, ErrorCode |
37 | 42 | from mypy.errors import ( |
38 | 43 | ErrorInfo, |
@@ -6690,8 +6695,7 @@ def narrow_type_by_identity_equality( |
6690 | 6695 | target = TypeRange(target_type, is_upper_bound=False) |
6691 | 6696 |
|
6692 | 6697 | if_map, else_map = conditional_types_to_typemaps( |
6693 | | - operands[i], |
6694 | | - *conditional_types(expr_type, [target], from_equality=True), |
| 6698 | + operands[i], *conditional_types(expr_type, [target], from_equality=True) |
6695 | 6699 | ) |
6696 | 6700 | if is_target_for_value_narrowing(get_proper_type(target_type)): |
6697 | 6701 | all_if_maps.append(if_map) |
@@ -6729,9 +6733,7 @@ def narrow_type_by_identity_equality( |
6729 | 6733 | if is_target_for_value_narrowing(get_proper_type(target_type)): |
6730 | 6734 | if_map, else_map = conditional_types_to_typemaps( |
6731 | 6735 | operands[i], |
6732 | | - *conditional_types( |
6733 | | - expr_type, [target], from_equality=True |
6734 | | - ), |
| 6736 | + *conditional_types(expr_type, [target], from_equality=True), |
6735 | 6737 | ) |
6736 | 6738 | all_else_maps.append(else_map) |
6737 | 6739 | continue |
@@ -8390,21 +8392,15 @@ def conditional_types( |
8390 | 8392 | # We erase generic args because values with different generic types can compare equal |
8391 | 8393 | # For instance, cast(list[str], []) and cast(list[int], []) |
8392 | 8394 | proposed_type = shallow_erase_type_for_equality(proposed_type) |
8393 | | - if not is_overlapping_types( |
8394 | | - current_type, proposed_type, ignore_promotions=False |
8395 | | - ): |
| 8395 | + if not is_overlapping_types(current_type, proposed_type, ignore_promotions=False): |
8396 | 8396 | # Equality narrowing is one of the places at runtime where subtyping with promotion |
8397 | 8397 | # does happen to match runtime semantics |
8398 | 8398 | # Expression is never of any type in proposed_type_ranges |
8399 | 8399 | return UninhabitedType(), default |
8400 | | - if not is_overlapping_types( |
8401 | | - current_type, proposed_type, ignore_promotions=True |
8402 | | - ): |
| 8400 | + if not is_overlapping_types(current_type, proposed_type, ignore_promotions=True): |
8403 | 8401 | return default, default |
8404 | 8402 | else: |
8405 | | - if not is_overlapping_types( |
8406 | | - current_type, proposed_type, ignore_promotions=True |
8407 | | - ): |
| 8403 | + if not is_overlapping_types(current_type, proposed_type, ignore_promotions=True): |
8408 | 8404 | # Expression is never of any type in proposed_type_ranges |
8409 | 8405 | return UninhabitedType(), default |
8410 | 8406 |
|
@@ -8653,10 +8649,7 @@ def reduce_and_conditional_type_maps(ms: list[TypeMap], *, use_meet: bool) -> Ty |
8653 | 8649 | return result |
8654 | 8650 |
|
8655 | 8651 |
|
8656 | | -BUILTINS_CUSTOM_EQ_CHECKS: Final = { |
8657 | | - "builtins.bytearray", |
8658 | | - "builtins.memoryview", |
8659 | | -} |
| 8652 | +BUILTINS_CUSTOM_EQ_CHECKS: Final = {"builtins.bytearray", "builtins.memoryview"} |
8660 | 8653 |
|
8661 | 8654 |
|
8662 | 8655 | def has_custom_eq_checks(t: Type) -> bool: |
|
0 commit comments