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

Method check_lst_expr

mypy/checkexpr.py:5225–5258  ·  view source on GitHub ↗
(self, e: ListExpr | SetExpr | TupleExpr, fullname: str, tag: str)

Source from the content-addressed store, hash-verified

5223 return typ
5224
5225 def check_lst_expr(self, e: ListExpr | SetExpr | TupleExpr, fullname: str, tag: str) -> Type:
5226 # fast path
5227 t = self.fast_container_type(e, fullname)
5228 if t:
5229 return t
5230
5231 # Translate into type checking a generic function call.
5232 # Used for list and set expressions, as well as for tuples
5233 # containing star expressions that don't refer to a
5234 # Tuple. (Note: "lst" stands for list-set-tuple. :-)
5235 tv = TypeVarType(
5236 "T",
5237 "T",
5238 id=TypeVarId(-1, namespace="<lst>"),
5239 values=[],
5240 upper_bound=self.object_type(),
5241 default=AnyType(TypeOfAny.from_omitted_generics),
5242 )
5243 constructor = CallableType(
5244 [tv],
5245 [nodes.ARG_STAR],
5246 [None],
5247 self.chk.named_generic_type(fullname, [tv]),
5248 self.named_type("builtins.function"),
5249 name=tag,
5250 variables=[tv],
5251 )
5252 out = self.check_call(
5253 constructor,
5254 [(i.expr if isinstance(i, StarExpr) else i) for i in e.items],
5255 [(nodes.ARG_STAR if isinstance(i, StarExpr) else nodes.ARG_POS) for i in e.items],
5256 e,
5257 )[0]
5258 return remove_instance_last_known_values(out)
5259
5260 def tuple_context_matches(self, expr: TupleExpr, ctx: TupleType) -> bool:
5261 ctx_unpack_index = find_unpack_in_list(ctx.items)

Callers 3

visit_list_exprMethod · 0.95
visit_set_exprMethod · 0.95
visit_tuple_exprMethod · 0.95

Calls 11

fast_container_typeMethod · 0.95
object_typeMethod · 0.95
named_typeMethod · 0.95
check_callMethod · 0.95
TypeVarTypeClass · 0.90
TypeVarIdClass · 0.90
AnyTypeClass · 0.90
CallableTypeClass · 0.90
isinstanceFunction · 0.85
named_generic_typeMethod · 0.45

Tested by

no test coverage detected