(left: RType, right: RType, *, relaxed: bool = False)
| 25 | |
| 26 | |
| 27 | def 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 | |
| 44 | class SubtypeVisitor(RTypeVisitor[bool]): |
searching dependent graphs…