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

Method visit_call_expr_inner

mypy/checkexpr.py:513–656  ·  view source on GitHub ↗
(self, e: CallExpr, allow_none_return: bool = False)

Source from the content-addressed store, hash-verified

511 )
512
513 def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) -> Type:
514 if (
515 self.refers_to_typeddict(e.callee)
516 or isinstance(e.callee, IndexExpr)
517 and self.refers_to_typeddict(e.callee.base)
518 ):
519 typeddict_callable = get_proper_type(self.accept(e.callee, is_callee=True))
520 if isinstance(typeddict_callable, CallableType):
521 typeddict_type = get_proper_type(typeddict_callable.ret_type)
522 assert isinstance(typeddict_type, TypedDictType)
523 return self.check_typeddict_call(
524 typeddict_type, e.arg_kinds, e.arg_names, e.args, e, typeddict_callable
525 )
526 if (
527 isinstance(e.callee, NameExpr)
528 and e.callee.name in ("isinstance", "issubclass")
529 and len(e.args) == 2
530 ):
531 for typ in mypy.checker.flatten(e.args[1]):
532 node = None
533 if isinstance(typ, NameExpr):
534 try:
535 node = self.chk.lookup_qualified(typ.name)
536 except KeyError:
537 # Undefined names should already be reported in semantic analysis.
538 pass
539 if is_expr_literal_type(typ):
540 self.msg.cannot_use_function_with_type(e.callee.name, "Literal", e)
541 continue
542 if node and isinstance(node.node, TypeAlias):
543 target = get_proper_type(node.node.target)
544 if isinstance(target, AnyType):
545 self.msg.cannot_use_function_with_type(e.callee.name, "Any", e)
546 continue
547 if isinstance(target, NoneType):
548 continue
549 if (
550 isinstance(typ, IndexExpr)
551 and isinstance(typ.analyzed, (TypeApplication, TypeAliasExpr))
552 ) or (
553 isinstance(typ, NameExpr)
554 and node
555 and isinstance(node.node, TypeAlias)
556 and not node.node.no_args
557 and not isinstance(get_proper_type(node.node.target), UnionType)
558 ):
559 self.msg.type_arguments_not_allowed(e)
560 if isinstance(typ, RefExpr) and isinstance(typ.node, TypeInfo):
561 if typ.node.typeddict_type:
562 self.msg.cannot_use_function_with_type(e.callee.name, "TypedDict", e)
563 elif typ.node.is_newtype:
564 self.msg.cannot_use_function_with_type(e.callee.name, "NewType", e)
565 self.try_infer_partial_type(e)
566 type_context = None
567 if isinstance(e.callee, LambdaExpr):
568 formal_to_actual = map_actuals_to_formals(
569 e.arg_kinds,
570 e.arg_names,

Callers 1

visit_call_exprMethod · 0.95

Calls 15

refers_to_typeddictMethod · 0.95
acceptMethod · 0.95
check_typeddict_callMethod · 0.95
object_typeMethod · 0.95
named_typeMethod · 0.95
method_fullnameMethod · 0.95
check_str_format_callMethod · 0.95
always_returns_noneMethod · 0.95

Tested by

no test coverage detected