4848 supports_membership_test ,
4949 supports_setitem ,
5050)
51+ from pylint .constants import PY310_PLUS
5152from pylint .interfaces import HIGH , INFERENCE
5253from pylint .typing import MessageDefinitionTuple
5354
@@ -796,6 +797,10 @@ def _is_c_extension(module_node: InferenceResult) -> bool:
796797
797798def _is_invalid_isinstance_type (arg : nodes .NodeNG ) -> bool :
798799 # 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+ )
799804 inferred = utils .safe_infer (arg )
800805 if not inferred :
801806 # Cannot infer it so skip it.
@@ -806,6 +811,10 @@ def _is_invalid_isinstance_type(arg: nodes.NodeNG) -> bool:
806811 return False
807812 if isinstance (inferred , astroid .Instance ) and inferred .qname () == BUILTIN_TUPLE :
808813 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 )
809818 return True
810819
811820
@@ -1398,7 +1407,11 @@ def _check_isinstance_args(self, node: nodes.Call) -> None:
13981407
13991408 second_arg = node .args [1 ]
14001409 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+ )
14021415
14031416 # pylint: disable = too-many-branches, too-many-locals, too-many-statements
14041417 def visit_call (self , node : nodes .Call ) -> None :
0 commit comments