(
functype: FunctionLike,
var: Var,
itype: Instance,
name: str,
mx: MemberContext,
is_trivial_self: bool,
)
| 963 | |
| 964 | |
| 965 | def 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 | |
| 1012 | def expand_self_type_if_needed( |
no test coverage detected
searching dependent graphs…