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

Function infer_reachability_of_match_statement

mypy/reachability.py:79–101  ·  view source on GitHub ↗
(s: MatchStmt, options: Options)

Source from the content-addressed store, hash-verified

77
78
79def infer_reachability_of_match_statement(s: MatchStmt, options: Options) -> None:
80 for i, guard in enumerate(s.guards):
81 pattern_value = infer_pattern_value(s.patterns[i])
82
83 if guard is not None:
84 guard_value = infer_condition_value(guard, options)
85 else:
86 guard_value = ALWAYS_TRUE
87
88 if pattern_value in (ALWAYS_FALSE, MYPY_FALSE) or guard_value in (
89 ALWAYS_FALSE,
90 MYPY_FALSE,
91 ):
92 # The case is considered always false, so we skip the case body.
93 mark_block_unreachable(s.bodies[i])
94 elif pattern_value in (ALWAYS_TRUE, MYPY_TRUE) and guard_value in (ALWAYS_TRUE, MYPY_TRUE):
95 for body in s.bodies[i + 1 :]:
96 mark_block_unreachable(body)
97
98 if guard_value == MYPY_TRUE:
99 # This condition is false at runtime; this will affect
100 # import priorities.
101 mark_block_mypy_only(s.bodies[i])
102
103
104def assert_will_always_fail(s: AssertStmt, options: Options) -> bool:

Callers 2

visit_match_stmtMethod · 0.90
visit_match_stmtMethod · 0.90

Calls 5

enumerateFunction · 0.85
infer_pattern_valueFunction · 0.85
infer_condition_valueFunction · 0.85
mark_block_unreachableFunction · 0.85
mark_block_mypy_onlyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…