This repository was archived by the owner on Jun 10, 2020. It is now read-only.
File tree 2 files changed +7
-10
lines changed
2 files changed +7
-10
lines changed Original file line number Diff line number Diff line change 1
1
from mypy .nodes import ARG_POS
2
2
from mypy .plugin import Plugin
3
3
from mypy .types import CallableType
4
-
5
- UFUNC_ARITIES = {
6
- 'sin' : 1 ,
7
- }
4
+ import numpy as np
8
5
9
6
10
7
def ufunc_call_hook (ctx ):
11
8
ufunc_name = ctx .context .callee .name
12
- arity = UFUNC_ARITIES . get ( ufunc_name )
13
- if arity is None :
9
+ ufunc = getattr ( np , ufunc_name , None )
10
+ if ufunc is None :
14
11
# No extra information; return the signature unmodified.
15
12
return ctx .default_signature
16
13
17
14
# Strip off the *args and replace it with the correct number of
18
15
# positional arguments.
19
- arg_kinds = [ARG_POS ] * arity + ctx .default_signature .arg_kinds [1 :]
16
+ arg_kinds = [ARG_POS ] * ufunc . nin + ctx .default_signature .arg_kinds [1 :]
20
17
arg_names = (
21
- [f'x{ i } ' for i in range (arity )] +
18
+ [f'x{ i } ' for i in range (ufunc . nin )] +
22
19
ctx .default_signature .arg_names [1 :]
23
20
)
24
21
arg_types = (
25
- [ctx .default_signature .arg_types [0 ]] * arity +
22
+ [ctx .default_signature .arg_types [0 ]] * ufunc . nin +
26
23
ctx .default_signature .arg_types [1 :]
27
24
)
28
25
return ctx .default_signature .copy_modified (
Original file line number Diff line number Diff line change 1
1
[mypy]
2
- plugins = numpy_ufuncs_plugin
2
+ plugins = numpy_ufuncs_plugin
You can’t perform that action at this time.
0 commit comments