Return block from IfStmt that will get executed. Return 0 -> A block if sure that alternative blocks are unreachable. 1 -> An IfStmt if the reachability of it can't be inferred, i.e. the truth value is unknown.
(
self, stmt: IfStmt
)
| 805 | return None |
| 806 | |
| 807 | def _get_executable_if_block_with_overloads( |
| 808 | self, stmt: IfStmt |
| 809 | ) -> tuple[Block | None, IfStmt | None]: |
| 810 | """Return block from IfStmt that will get executed. |
| 811 | |
| 812 | Return |
| 813 | 0 -> A block if sure that alternative blocks are unreachable. |
| 814 | 1 -> An IfStmt if the reachability of it can't be inferred, |
| 815 | i.e. the truth value is unknown. |
| 816 | """ |
| 817 | infer_reachability_of_if_statement(stmt, self.options) |
| 818 | if stmt.else_body is None and stmt.body[0].is_unreachable is True: |
| 819 | # always False condition with no else |
| 820 | return None, None |
| 821 | if ( |
| 822 | stmt.else_body is None |
| 823 | or stmt.body[0].is_unreachable is False |
| 824 | and stmt.else_body.is_unreachable is False |
| 825 | ): |
| 826 | # The truth value is unknown, thus not conclusive |
| 827 | return None, stmt |
| 828 | if stmt.else_body.is_unreachable is True: |
| 829 | # else_body will be set unreachable if condition is always True |
| 830 | return stmt.body[0], None |
| 831 | if stmt.body[0].is_unreachable is True: |
| 832 | # body will be set unreachable if condition is always False |
| 833 | # else_body can contain an IfStmt itself (for elif) -> do a recursive check |
| 834 | if isinstance(stmt.else_body.body[0], IfStmt): |
| 835 | return self._get_executable_if_block_with_overloads(stmt.else_body.body[0]) |
| 836 | return stmt.else_body, None |
| 837 | return None, stmt |
| 838 | |
| 839 | def _strip_contents_from_if_stmt(self, stmt: IfStmt) -> None: |
| 840 | """Remove contents from IfStmt. |
no test coverage detected