MCPcopy
hub / github.com/pytorch/pytorch / _isinstance

Function _isinstance

torch/_jit_internal.py:1435–1457  ·  view source on GitHub ↗
(obj, target_type)

Source from the content-addressed store, hash-verified

1433
1434
1435def _isinstance(obj, target_type) -> bool:
1436 if isinstance(target_type, collections.abc.Container):
1437 if not isinstance(target_type, tuple):
1438 raise RuntimeError(
1439 "The second argument to "
1440 "`torch.jit.isinstance` must be a type "
1441 "or a tuple of types"
1442 )
1443 for t_type in target_type:
1444 if _isinstance(obj, t_type):
1445 return True
1446 return False
1447
1448 origin_type = get_origin(target_type)
1449 if origin_type:
1450 return container_checker(obj, target_type)
1451
1452 # Check to handle non-typed optional origin returns as none instead
1453 # of as optional in 3.7-3.8
1454 check_args_exist(target_type)
1455
1456 # handle non-containers
1457 return isinstance(obj, target_type)
1458
1459
1460class _TensorExtractor(pickle.Pickler):

Callers 1

isinstanceFunction · 0.90

Calls 3

isinstanceFunction · 0.85
container_checkerFunction · 0.85
check_args_existFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…