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

Method visit_singleton_pattern

mypy/checkpattern.py:218–231  ·  view source on GitHub ↗
(self, o: SingletonPattern)

Source from the content-addressed store, hash-verified

216 return PatternType(ok_type, rest_type, {})
217
218 def visit_singleton_pattern(self, o: SingletonPattern) -> PatternType:
219 current_type = self.type_context[-1]
220 value: bool | None = o.value
221 if isinstance(value, bool):
222 typ = self.chk.expr_checker.infer_literal_expr_type(value, "builtins.bool")
223 elif value is None:
224 typ = NoneType()
225 else:
226 assert False
227
228 narrowed_type, rest_type = self.chk.conditional_types_with_intersection(
229 current_type, [get_type_range(typ)], o, default=current_type
230 )
231 return PatternType(narrowed_type, rest_type, {})
232
233 def visit_sequence_pattern(self, o: SequencePattern) -> PatternType:
234 #

Callers

nothing calls this directly

Calls 6

NoneTypeClass · 0.90
isinstanceFunction · 0.85
get_type_rangeFunction · 0.85
PatternTypeClass · 0.85

Tested by

no test coverage detected