MCPcopy Index your code
hub / github.com/python/mypy / is_subtype

Function is_subtype

mypyc/subtype.py:27–41  ·  view source on GitHub ↗
(left: RType, right: RType, *, relaxed: bool = False)

Source from the content-addressed store, hash-verified

25
26
27def is_subtype(left: RType, right: RType, *, relaxed: bool = False) -> bool:
28 if is_object_rprimitive(right):
29 return True
30 elif isinstance(right, RUnion):
31 if isinstance(left, RUnion):
32 for left_item in left.items:
33 if not any(
34 is_subtype(left_item, right_item, relaxed=relaxed)
35 for right_item in right.items
36 ):
37 return False
38 return True
39 else:
40 return any(is_subtype(left, item, relaxed=relaxed) for item in right.items)
41 return left.accept(SubtypeVisitor(right, relaxed=relaxed))
42
43
44class SubtypeVisitor(RTypeVisitor[bool]):

Callers 15

visit_rinstanceMethod · 0.90
visit_runionMethod · 0.90
gen_glue_ne_methodFunction · 0.90
coerceMethod · 0.90
coerce_nullableMethod · 0.90
dunder_opMethod · 0.90
matching_call_cMethod · 0.90
matching_primitive_opMethod · 0.90
test_bitMethod · 0.90
test_boolMethod · 0.90
test_int64Method · 0.90
test_int32Method · 0.90

Calls 5

is_object_rprimitiveFunction · 0.90
isinstanceFunction · 0.85
anyFunction · 0.85
SubtypeVisitorClass · 0.70
acceptMethod · 0.45

Tested by 6

test_bitMethod · 0.72
test_boolMethod · 0.72
test_int64Method · 0.72
test_int32Method · 0.72
test_int16Method · 0.72
assert_emit_binary_opMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…