def _create_new_partial(self) -> MypyType: """ Creates a new partial function-like from set of callables. We also need fallbacks here, because sometimes there are no possible ways to create at least a single partial case. In this scenario we analyze the set of fallbacks and tell user what went wrong. """ if not self._case_functions: analyze_call( proper_type(self._fallbacks), self._applied_args, self._ctx, show_errors=True, ) return self._default_return_type return proper_type(self._case_functions)
def _create_intermediate( self, case_function: CallableType, ) -> Tuple[CallableType, Optional[CallableType]]: intermediate = Intermediate(case_function).with_applied_args( self._applied_args, ) return intermediate, analyze_call( intermediate, self._applied_args, self._ctx, show_errors=False, )
def factory(ctx: FunctionContext) -> MypyType: if not (sym and sym.type and isinstance(sym.type, CallableType)): return ctx.default_return_type arg = ctx.api.expr_checker.accept(ctx.args[0][0]) # type: ignore tp = analtype.analyze_call( sym.type, [FuncArg(None, arg, ARG_POS)], ctx, show_errors=False, ) if not (isinstance(arg, CallableType) and isinstance(tp, CallableType)): return ctx.default_return_type if not isinstance(tp.ret_type, CallableType): return ctx.default_return_type return _change_decorator_function_type(tp.ret_type, arg)
def from_callable_sequence( self, pipeline_types: List[MypyType], pipeline_kinds: List[int], ctx: CallableContext, ) -> MypyType: """Pass pipeline functions to infer them one by one.""" parameter = FuncArg(None, self._instance, ARG_POS) ret_type = ctx.default_return_type for pipeline, kind in zip(pipeline_types, pipeline_kinds): ret_type = self._proper_type( analyze_call( cast(FunctionLike, pipeline), [parameter], ctx, show_errors=True, ), ) parameter = FuncArg(None, ret_type, kind) return ret_type