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

Method visit_value_pattern

mypy/checkpattern.py:204–216  ·  view source on GitHub ↗
(self, o: ValuePattern)

Source from the content-addressed store, hash-verified

202 return PatternType(union_type, current_type, captures)
203
204 def visit_value_pattern(self, o: ValuePattern) -> PatternType:
205 current_type = self.type_context[-1]
206 typ = self.chk.expr_checker.accept(o.expr)
207 typ = coerce_to_literal(typ)
208 node = TempNode(current_type)
209 # Value patterns are essentially a syntactic sugar on top of `if x == Value`.
210 # They should be treated equivalently.
211 ok_map, rest_map = self.chk.narrow_type_by_identity_equality(
212 "==", [node, TempNode(typ)], [current_type, typ], [0, 1], {0}
213 )
214 ok_type = ok_map.get(node, current_type) if ok_map is not None else UninhabitedType()
215 rest_type = rest_map.get(node, current_type) if rest_map is not None else UninhabitedType()
216 return PatternType(ok_type, rest_type, {})
217
218 def visit_singleton_pattern(self, o: SingletonPattern) -> PatternType:
219 current_type = self.type_context[-1]

Callers

nothing calls this directly

Calls 7

coerce_to_literalFunction · 0.90
TempNodeClass · 0.90
UninhabitedTypeClass · 0.90
PatternTypeClass · 0.85
acceptMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected