1+ from collections .abc import Sequence
12from types import MappingProxyType
2- from typing import Final , Literal , overload
3+ from typing import Any , Final , Literal , overload
34
45from mypy .checkmember import analyze_member_access
56from mypy .nodes import ARG_NAMED , ARG_OPT
67from mypy .types import CallableType , FunctionLike , ProperType , get_proper_type
78from mypy .types import Type as MypyType
9+ from mypy .version import __version__ as mypy_version
810
911from returns .contrib .mypy ._structures .args import FuncArg
1012from returns .contrib .mypy ._structures .types import CallableContext
2123@overload
2224def analyze_call (
2325 function : FunctionLike ,
24- args : list [FuncArg ],
26+ args : Sequence [FuncArg ],
2527 ctx : CallableContext ,
2628 * ,
2729 show_errors : Literal [True ],
@@ -31,14 +33,20 @@ def analyze_call(
3133@overload
3234def analyze_call (
3335 function : FunctionLike ,
34- args : list [FuncArg ],
36+ args : Sequence [FuncArg ],
3537 ctx : CallableContext ,
3638 * ,
3739 show_errors : bool ,
3840) -> CallableType | None : ...
3941
4042
41- def analyze_call (function , args , ctx , * , show_errors ):
43+ def analyze_call (
44+ function : FunctionLike ,
45+ args : Sequence [FuncArg ],
46+ ctx : CallableContext ,
47+ * ,
48+ show_errors : bool ,
49+ ) -> CallableType | None :
4250 """
4351 Analyzes function call based on passed arguments.
4452
@@ -48,7 +56,7 @@ def analyze_call(function, args, ctx, *, show_errors):
4856 We also allow to return ``None`` instead of showing errors.
4957 This might be helpful for cases when we run intermediate analysis.
5058 """
51- checker = ctx .api .expr_checker
59+ checker = ctx .api .expr_checker # type: ignore[attr-defined]
5260 with checker .msg .filter_errors (save_filtered_errors = True ) as local_errors :
5361 _return_type , checked_function = checker .check_call (
5462 function ,
@@ -63,7 +71,7 @@ def analyze_call(function, args, ctx, *, show_errors):
6371
6472 checker .msg .add_errors (local_errors .filtered_errors ()) # noqa: WPS441
6573
66- return checked_function
74+ return checked_function # type: ignore[no-any-return]
6775
6876
6977def safe_translate_to_function (
@@ -110,6 +118,15 @@ def translate_to_function(
110118 This also preserves all type arguments as-is.
111119 """
112120 checker = ctx .api .expr_checker # type: ignore
121+
122+ mypy_version_tuple = tuple (
123+ map (int , mypy_version .partition ('+' )[0 ].split ('.' ))
124+ )
125+
126+ extra_kwargs : dict [str , Any ] = {}
127+ if mypy_version_tuple > (1 , 16 ):
128+ extra_kwargs ['msg' ] = checker .msg
129+
113130 return get_proper_type (
114131 analyze_member_access (
115132 '__call__' ,
@@ -118,9 +135,8 @@ def translate_to_function(
118135 is_lvalue = False ,
119136 is_super = False ,
120137 is_operator = True ,
121- msg = checker .msg ,
122138 original_type = function_def ,
123139 chk = checker .chk ,
124- in_literal_context = checker . is_literal_context () ,
140+ ** extra_kwargs ,
125141 )
126142 )
0 commit comments