@@ -4096,7 +4096,7 @@ def lookup_definer(typ: Instance, attr_name: str) -> str | None:
40964096 results = []
40974097 for name , method , obj , arg in variants :
40984098 with self .msg .filter_errors (save_filtered_errors = True ) as local_errors :
4099- result = self .check_method_call (op_name , obj , method , [arg ], [ARG_POS ], context )
4099+ result = self .check_method_call (name , obj , method , [arg ], [ARG_POS ], context )
41004100 if local_errors .has_new_errors ():
41014101 errors .append (local_errors .filtered_errors ())
41024102 results .append (result )
@@ -4696,8 +4696,8 @@ def visit_cast_expr(self, expr: CastExpr) -> Type:
46964696 options = self .chk .options
46974697 if (
46984698 options .warn_redundant_casts
4699- and not isinstance ( get_proper_type ( target_type ) , AnyType )
4700- and source_type == target_type
4699+ and not is_same_type ( target_type , AnyType ( TypeOfAny . special_form ) )
4700+ and is_same_type ( source_type , target_type )
47014701 ):
47024702 self .msg .redundant_cast (target_type , expr )
47034703 if options .disallow_any_unimported and has_any_from_unimported_type (target_type ):
@@ -6297,7 +6297,13 @@ def narrow_type_from_binder(
62976297 known_type , restriction , prohibit_none_typevar_overlap = True
62986298 ):
62996299 return None
6300- return narrow_declared_type (known_type , restriction )
6300+ narrowed = narrow_declared_type (known_type , restriction )
6301+ if isinstance (get_proper_type (narrowed ), UninhabitedType ):
6302+ # If we hit this case, it means that we can't reliably mark the code as
6303+ # unreachable, but the resulting type can't be expressed in type system.
6304+ # Falling back to restriction is more intuitive in most cases.
6305+ return restriction
6306+ return narrowed
63016307 return known_type
63026308
63036309 def has_abstract_type_part (self , caller_type : ProperType , callee_type : ProperType ) -> bool :
0 commit comments