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

Function expand_and_bind_callable

mypy/checkmember.py:965–1009  ·  view source on GitHub ↗
(
    functype: FunctionLike,
    var: Var,
    itype: Instance,
    name: str,
    mx: MemberContext,
    is_trivial_self: bool,
)

Source from the content-addressed store, hash-verified

963
964
965def expand_and_bind_callable(
966 functype: FunctionLike,
967 var: Var,
968 itype: Instance,
969 name: str,
970 mx: MemberContext,
971 is_trivial_self: bool,
972) -> Type:
973 if not mx.preserve_type_var_ids:
974 functype = freshen_all_functions_type_vars(functype)
975 typ = get_proper_type(expand_self_type(var, functype, mx.self_type))
976 assert isinstance(typ, FunctionLike)
977 if is_trivial_self:
978 typ = bind_self_fast(typ, mx.self_type)
979 else:
980 typ = check_self_arg(typ, mx.self_type, var.is_classmethod, mx.context, name, mx.msg)
981 typ = bind_self(typ, mx.self_type, var.is_classmethod)
982 expanded = expand_type_by_instance(typ, itype)
983 freeze_all_type_vars(expanded)
984 if not var.is_property:
985 return expanded
986 if isinstance(expanded, Overloaded):
987 # Legacy way to store settable properties is with overloads. Also in case it is
988 # an actual overloaded property, selecting first item that passed check_self_arg()
989 # is a good approximation, long-term we should use check_call() inference below.
990 if not expanded.items:
991 # A broken overload, error should be already reported.
992 return AnyType(TypeOfAny.from_error)
993 expanded = expanded.items[0]
994 assert isinstance(expanded, CallableType), expanded
995 if var.is_settable_property and mx.is_lvalue and var.setter_type is not None:
996 if expanded.variables:
997 type_ctx = mx.rvalue or TempNode(AnyType(TypeOfAny.special_form), context=mx.context)
998 _, inferred_expanded = mx.chk.expr_checker.check_call(
999 expanded, [type_ctx], [ARG_POS], mx.context
1000 )
1001 expanded = get_proper_type(inferred_expanded)
1002 assert isinstance(expanded, CallableType)
1003 if not expanded.arg_types:
1004 # This can happen when accessing invalid property from its own body,
1005 # error will be reported elsewhere.
1006 return AnyType(TypeOfAny.from_error)
1007 return expanded.arg_types[0]
1008 else:
1009 return expanded.ret_type
1010
1011
1012def expand_self_type_if_needed(

Callers 1

analyze_varFunction · 0.85

Calls 12

get_proper_typeFunction · 0.90
expand_self_typeFunction · 0.90
bind_selfFunction · 0.90
expand_type_by_instanceFunction · 0.90
freeze_all_type_varsFunction · 0.90
AnyTypeClass · 0.90
TempNodeClass · 0.90
isinstanceFunction · 0.85
bind_self_fastFunction · 0.85
check_self_argFunction · 0.85
check_callMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…