@@ -3980,17 +3980,15 @@ def _is_truthy_instance(t: Type) -> bool:
3980
3980
not t .type .has_readable_member ('__len__' )
3981
3981
)
3982
3982
3983
- def _check_for_truthy_type (self , t : Type , name : str , context : Context ) -> None :
3983
+ def _check_for_truthy_type (self , t : Type , node : Node ) -> None :
3984
3984
if self ._is_truthy_instance (t ):
3985
3985
self .msg .note (
3986
3986
"{} has type '{}' which does not implement __bool__ or __len__ "
3987
- "so it will always be truthy in boolean context" .format (name , t ), context )
3988
- elif isinstance (t , UnionType ) and all (
3989
- self ._is_truthy_instance (t ) for t in t .items
3990
- ):
3987
+ "so it will always be truthy in boolean context" .format (node , t ), node )
3988
+ elif isinstance (t , UnionType ) and all (self ._is_truthy_instance (t ) for t in t .items ):
3991
3989
self .msg .note (
3992
3990
"{} has type '{}' where none of the members implement __bool__ or __len__ "
3993
- "so it will always be truthy in boolean context" .format (name , t ), context )
3991
+ "so it will always be truthy in boolean context" .format (node , t ), node )
3994
3992
3995
3993
def find_type_equals_check (self , node : ComparisonExpr , expr_indices : List [int ]
3996
3994
) -> Tuple [TypeMap , TypeMap ]:
@@ -4089,6 +4087,7 @@ def find_isinstance_check(self, node: Expression
4089
4087
4090
4088
def find_isinstance_check_helper (self , node : Expression ) -> Tuple [TypeMap , TypeMap ]:
4091
4089
type_map = self .type_map
4090
+
4092
4091
if is_true_literal (node ):
4093
4092
return {}, None
4094
4093
elif is_false_literal (node ):
@@ -4125,7 +4124,7 @@ def find_isinstance_check_helper(self, node: Expression) -> Tuple[TypeMap, TypeM
4125
4124
if literal (expr ) == LITERAL_TYPE :
4126
4125
return {expr : TypeGuardType (node .callee .type_guard )}, {}
4127
4126
4128
- self ._check_for_truthy_type (type_map [node ], name = f'return value of { node . callee . fullname } ' , context = node )
4127
+ self ._check_for_truthy_type (type_map [node ], node )
4129
4128
4130
4129
return {}, {}
4131
4130
elif isinstance (node , ComparisonExpr ):
@@ -4279,7 +4278,7 @@ def has_no_custom_eq_checks(t: Type) -> bool:
4279
4278
# Restrict the type of the variable to True-ish/False-ish in the if and else branches
4280
4279
# respectively
4281
4280
vartype = type_map [node ]
4282
- self ._check_for_truthy_type (vartype , name = node . fullname , context = node )
4281
+ self ._check_for_truthy_type (vartype , node )
4283
4282
if_type = true_only (vartype ) # type: Type
4284
4283
else_type = false_only (vartype ) # type: Type
4285
4284
ref = node # type: Expression
@@ -4308,7 +4307,6 @@ def has_no_custom_eq_checks(t: Type) -> bool:
4308
4307
elif isinstance (node , UnaryExpr ) and node .op == 'not' :
4309
4308
left , right = self .find_isinstance_check_helper (node .expr )
4310
4309
return right , left
4311
-
4312
4310
# Not a supported isinstance check
4313
4311
return {}, {}
4314
4312
0 commit comments