@@ -6009,6 +6009,7 @@ def find_isinstance_check_helper(
60096009 self .lookup_type (expr ),
60106010 [TypeRange (node .callee .type_is , is_upper_bound = False )],
60116011 expr ,
6012+ consider_runtime_isinstance = False ,
60126013 ),
60136014 )
60146015 elif isinstance (node , ComparisonExpr ):
@@ -7419,11 +7420,19 @@ def conditional_types_with_intersection(
74197420 type_ranges : list [TypeRange ] | None ,
74207421 ctx : Context ,
74217422 default : None = None ,
7423+ * ,
7424+ consider_runtime_isinstance : bool = True ,
74227425 ) -> tuple [Type | None , Type | None ]: ...
74237426
74247427 @overload
74257428 def conditional_types_with_intersection (
7426- self , expr_type : Type , type_ranges : list [TypeRange ] | None , ctx : Context , default : Type
7429+ self ,
7430+ expr_type : Type ,
7431+ type_ranges : list [TypeRange ] | None ,
7432+ ctx : Context ,
7433+ default : Type ,
7434+ * ,
7435+ consider_runtime_isinstance : bool = True ,
74277436 ) -> tuple [Type , Type ]: ...
74287437
74297438 def conditional_types_with_intersection (
@@ -7432,8 +7441,15 @@ def conditional_types_with_intersection(
74327441 type_ranges : list [TypeRange ] | None ,
74337442 ctx : Context ,
74347443 default : Type | None = None ,
7444+ * ,
7445+ consider_runtime_isinstance : bool = True ,
74357446 ) -> tuple [Type | None , Type | None ]:
7436- initial_types = conditional_types (expr_type , type_ranges , default )
7447+ initial_types = conditional_types (
7448+ expr_type ,
7449+ type_ranges ,
7450+ default ,
7451+ consider_runtime_isinstance = consider_runtime_isinstance ,
7452+ )
74377453 # For some reason, doing "yes_map, no_map = conditional_types_to_typemaps(...)"
74387454 # doesn't work: mypyc will decide that 'yes_map' is of type None if we try.
74397455 yes_type : Type | None = initial_types [0 ]
@@ -7712,18 +7728,30 @@ def visit_type_var(self, t: TypeVarType) -> None:
77127728
77137729@overload
77147730def conditional_types (
7715- current_type : Type , proposed_type_ranges : list [TypeRange ] | None , default : None = None
7731+ current_type : Type ,
7732+ proposed_type_ranges : list [TypeRange ] | None ,
7733+ default : None = None ,
7734+ * ,
7735+ consider_runtime_isinstance : bool = True ,
77167736) -> tuple [Type | None , Type | None ]: ...
77177737
77187738
77197739@overload
77207740def conditional_types (
7721- current_type : Type , proposed_type_ranges : list [TypeRange ] | None , default : Type
7741+ current_type : Type ,
7742+ proposed_type_ranges : list [TypeRange ] | None ,
7743+ default : Type ,
7744+ * ,
7745+ consider_runtime_isinstance : bool = True ,
77227746) -> tuple [Type , Type ]: ...
77237747
77247748
77257749def conditional_types (
7726- current_type : Type , proposed_type_ranges : list [TypeRange ] | None , default : Type | None = None
7750+ current_type : Type ,
7751+ proposed_type_ranges : list [TypeRange ] | None ,
7752+ default : Type | None = None ,
7753+ * ,
7754+ consider_runtime_isinstance : bool = True ,
77277755) -> tuple [Type | None , Type | None ]:
77287756 """Takes in the current type and a proposed type of an expression.
77297757
@@ -7765,7 +7793,11 @@ def conditional_types(
77657793 if not type_range .is_upper_bound
77667794 ]
77677795 )
7768- remaining_type = restrict_subtype_away (current_type , proposed_precise_type )
7796+ remaining_type = restrict_subtype_away (
7797+ current_type ,
7798+ proposed_precise_type ,
7799+ consider_runtime_isinstance = consider_runtime_isinstance ,
7800+ )
77697801 return proposed_type , remaining_type
77707802 else :
77717803 # An isinstance check, but we don't understand the type
0 commit comments