1
+ from collections .abc import Sequence
1
2
from types import MappingProxyType
2
- from typing import Final , Literal , overload
3
+ from typing import Any , Final , Literal , overload
3
4
4
5
from mypy .checkmember import analyze_member_access
5
6
from mypy .nodes import ARG_NAMED , ARG_OPT
6
7
from mypy .types import CallableType , FunctionLike , ProperType , get_proper_type
7
8
from mypy .types import Type as MypyType
9
+ from mypy .version import __version__ as mypy_version
8
10
9
11
from returns .contrib .mypy ._structures .args import FuncArg
10
12
from returns .contrib .mypy ._structures .types import CallableContext
21
23
@overload
22
24
def analyze_call (
23
25
function : FunctionLike ,
24
- args : list [FuncArg ],
26
+ args : Sequence [FuncArg ],
25
27
ctx : CallableContext ,
26
28
* ,
27
29
show_errors : Literal [True ],
@@ -31,14 +33,20 @@ def analyze_call(
31
33
@overload
32
34
def analyze_call (
33
35
function : FunctionLike ,
34
- args : list [FuncArg ],
36
+ args : Sequence [FuncArg ],
35
37
ctx : CallableContext ,
36
38
* ,
37
39
show_errors : bool ,
38
40
) -> CallableType | None : ...
39
41
40
42
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 :
42
50
"""
43
51
Analyzes function call based on passed arguments.
44
52
@@ -48,7 +56,7 @@ def analyze_call(function, args, ctx, *, show_errors):
48
56
We also allow to return ``None`` instead of showing errors.
49
57
This might be helpful for cases when we run intermediate analysis.
50
58
"""
51
- checker = ctx .api .expr_checker
59
+ checker = ctx .api .expr_checker # type: ignore[attr-defined]
52
60
with checker .msg .filter_errors (save_filtered_errors = True ) as local_errors :
53
61
_return_type , checked_function = checker .check_call (
54
62
function ,
@@ -63,7 +71,7 @@ def analyze_call(function, args, ctx, *, show_errors):
63
71
64
72
checker .msg .add_errors (local_errors .filtered_errors ()) # noqa: WPS441
65
73
66
- return checked_function
74
+ return checked_function # type: ignore[no-any-return]
67
75
68
76
69
77
def safe_translate_to_function (
@@ -110,6 +118,15 @@ def translate_to_function(
110
118
This also preserves all type arguments as-is.
111
119
"""
112
120
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
+
113
130
return get_proper_type (
114
131
analyze_member_access (
115
132
'__call__' ,
@@ -118,9 +135,8 @@ def translate_to_function(
118
135
is_lvalue = False ,
119
136
is_super = False ,
120
137
is_operator = True ,
121
- msg = checker .msg ,
122
138
original_type = function_def ,
123
139
chk = checker .chk ,
124
- in_literal_context = checker . is_literal_context () ,
140
+ ** extra_kwargs ,
125
141
)
126
142
)
0 commit comments