MCPcopy
hub / github.com/python/mypy / visit_template_str_expr

Method visit_template_str_expr

mypy/checkexpr.py:5559–5574  ·  view source on GitHub ↗

Type check a template string expression (t-string). Type-checks all interpolated expressions but the result is always string.templatelib.Template.

(self, e: TemplateStrExpr)

Source from the content-addressed store, hash-verified

5557 return [], False
5558
5559 def visit_template_str_expr(self, e: TemplateStrExpr) -> Type:
5560 """Type check a template string expression (t-string).
5561
5562 Type-checks all interpolated expressions but the result is always
5563 string.templatelib.Template.
5564 """
5565 for item in e.items:
5566 if isinstance(item, tuple):
5567 value_expr, _source, _conversion, format_spec = item
5568 self.accept(value_expr)
5569 if format_spec is not None:
5570 self.accept(format_spec)
5571 sym = lookup_fully_qualified("string.templatelib.Template", self.chk.modules)
5572 if sym is not None and isinstance(sym.node, TypeInfo):
5573 return Instance(sym.node, [])
5574 return AnyType(TypeOfAny.from_error)
5575
5576 def visit_lambda_expr(self, e: LambdaExpr) -> Type:
5577 """Type check lambda expression."""

Callers

nothing calls this directly

Calls 5

acceptMethod · 0.95
lookup_fully_qualifiedFunction · 0.90
InstanceClass · 0.90
AnyTypeClass · 0.90
isinstanceFunction · 0.85

Tested by

no test coverage detected