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

Function get_executable_if_block_with_overloads

mypy/nativeparse.py:1772–1802  ·  view source on GitHub ↗

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.

(
    stmt: IfStmt, options: Options
)

Source from the content-addressed store, hash-verified

1770
1771
1772def get_executable_if_block_with_overloads(
1773 stmt: IfStmt, options: Options
1774) -> tuple[Block | None, IfStmt | None]:
1775 """Return block from IfStmt that will get executed.
1776
1777 Return
1778 0 -> A block if sure that alternative blocks are unreachable.
1779 1 -> An IfStmt if the reachability of it can't be inferred,
1780 i.e. the truth value is unknown.
1781 """
1782 infer_reachability_of_if_statement(stmt, options)
1783 if stmt.else_body is None and stmt.body[0].is_unreachable is True:
1784 # always False condition with no else
1785 return None, None
1786 if (
1787 stmt.else_body is None
1788 or stmt.body[0].is_unreachable is False
1789 and stmt.else_body.is_unreachable is False
1790 ):
1791 # The truth value is unknown, thus not conclusive
1792 return None, stmt
1793 if stmt.else_body.is_unreachable:
1794 # else_body will be set unreachable if condition is always True
1795 return stmt.body[0], None
1796 if stmt.body[0].is_unreachable is True:
1797 # body will be set unreachable if condition is always False
1798 # else_body can contain an IfStmt itself (for elif) -> do a recursive check
1799 if isinstance(stmt.else_body.body[0], IfStmt):
1800 return get_executable_if_block_with_overloads(stmt.else_body.body[0], options)
1801 return stmt.else_body, None
1802 return None, stmt
1803
1804
1805def fix_function_overloads(state: State, stmts: list[Statement]) -> list[Statement]:

Callers 1

fix_function_overloadsFunction · 0.85

Calls 2

isinstanceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…