48
48
supports_membership_test ,
49
49
supports_setitem ,
50
50
)
51
+ from pylint .constants import PY310_PLUS
51
52
from pylint .interfaces import HIGH , INFERENCE
52
53
from pylint .typing import MessageDefinitionTuple
53
54
@@ -796,6 +797,10 @@ def _is_c_extension(module_node: InferenceResult) -> bool:
796
797
797
798
def _is_invalid_isinstance_type (arg : nodes .NodeNG ) -> bool :
798
799
# Return True if we are sure that arg is not a type
800
+ if PY310_PLUS and isinstance (arg , nodes .BinOp ) and arg .op == "|" :
801
+ return _is_invalid_isinstance_type (arg .left ) or _is_invalid_isinstance_type (
802
+ arg .right
803
+ )
799
804
inferred = utils .safe_infer (arg )
800
805
if not inferred :
801
806
# Cannot infer it so skip it.
@@ -806,6 +811,10 @@ def _is_invalid_isinstance_type(arg: nodes.NodeNG) -> bool:
806
811
return False
807
812
if isinstance (inferred , astroid .Instance ) and inferred .qname () == BUILTIN_TUPLE :
808
813
return False
814
+ if PY310_PLUS and isinstance (inferred , bases .UnionType ):
815
+ return _is_invalid_isinstance_type (
816
+ inferred .left
817
+ ) or _is_invalid_isinstance_type (inferred .right )
809
818
return True
810
819
811
820
@@ -1398,7 +1407,11 @@ def _check_isinstance_args(self, node: nodes.Call) -> None:
1398
1407
1399
1408
second_arg = node .args [1 ]
1400
1409
if _is_invalid_isinstance_type (second_arg ):
1401
- self .add_message ("isinstance-second-argument-not-valid-type" , node = node )
1410
+ self .add_message (
1411
+ "isinstance-second-argument-not-valid-type" ,
1412
+ node = node ,
1413
+ confidence = INFERENCE ,
1414
+ )
1402
1415
1403
1416
# pylint: disable = too-many-branches, too-many-locals, too-many-statements
1404
1417
def visit_call (self , node : nodes .Call ) -> None :
0 commit comments