This repository was archived by the owner on Jun 10, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +18
-9
lines changed Expand file tree Collapse file tree 2 files changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ from typing import (
28
28
TypeVar ,
29
29
Union ,
30
30
)
31
+ from typing_extensions import Literal
31
32
32
33
if sys .version_info [0 ] < 3 :
33
34
class SupportsBytes : ...
@@ -619,7 +620,10 @@ WRAP: int
619
620
little_endian : int
620
621
tracemalloc_domain : int
621
622
622
- class ufunc :
623
+ _Nin = TypeVar ('_Nin' , bound = int )
624
+ _Nout = TypeVar ('_Nout' , bound = int )
625
+
626
+ class ufunc (Generic [_Nin ], Generic [_Nout ]):
623
627
@property
624
628
def __name__ (self ) -> str : ...
625
629
def __call__ (
@@ -765,7 +769,7 @@ right_shift: ufunc
765
769
rint : ufunc
766
770
sign : ufunc
767
771
signbit : ufunc
768
- sin : ufunc
772
+ sin : ufunc [ Literal [ 1 ], Literal [ 1 ]]
769
773
sinh : ufunc
770
774
spacing : ufunc
771
775
sqrt : ufunc
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
- import numpy as np
5
4
6
5
7
6
def ufunc_call_hook (ctx ):
8
7
ufunc_name = ctx .context .callee .name
9
- ufunc = getattr (np , ufunc_name , None )
10
- if ufunc is None :
11
- # No extra information; return the signature unmodified.
8
+
9
+ type_info = ctx .type .serialize ()
10
+ nin_arg , nout_arg = type_info ['args' ]
11
+ if nin_arg ['.class' ] != 'LiteralType' :
12
+ return ctx .default_signature
13
+ if nout_arg ['.class' ] != 'LiteralType' :
12
14
return ctx .default_signature
13
15
16
+ nin = nin_arg ['value' ]
17
+ nout = nout_arg ['value' ]
18
+
14
19
# Strip off the *args and replace it with the correct number of
15
20
# positional arguments.
16
- arg_kinds = [ARG_POS ] * ufunc . nin + ctx .default_signature .arg_kinds [1 :]
21
+ arg_kinds = [ARG_POS ] * nin + ctx .default_signature .arg_kinds [1 :]
17
22
arg_names = (
18
- [f'x{ i } ' for i in range (ufunc . nin )] +
23
+ [f'x{ i } ' for i in range (nin )] +
19
24
ctx .default_signature .arg_names [1 :]
20
25
)
21
26
arg_types = (
22
- [ctx .default_signature .arg_types [0 ]] * ufunc . nin +
27
+ [ctx .default_signature .arg_types [0 ]] * nin +
23
28
ctx .default_signature .arg_types [1 :]
24
29
)
25
30
return ctx .default_signature .copy_modified (
You can’t perform that action at this time.
0 commit comments