Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit ce0defe

Browse files
committed
add new python typing
1 parent 0be9331 commit ce0defe

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed

numba_typing/new_typing.py

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import typing
2+
import numpy as np
3+
import pandas as pd
4+
from abc import abstractmethod
5+
import typing_extensions
6+
7+
T = typing.TypeVar('T')
8+
S = typing.TypeVar('S')
9+
10+
11+
class Array(typing.Generic[T, S]):
12+
'''Annotation for np.ndarray
13+
Use square brackets to indicate type and dimension
14+
For example: Array[int, typing_extensions.Literal[4]]'''
15+
__slots__ = ()
16+
17+
@abstractmethod
18+
def __array__(self) -> np.ndarray:
19+
pass
20+
21+
22+
class Series(typing.Generic[T, S]):
23+
'''Annotation for pandas.Series
24+
For expample: Series[int, str]
25+
int - type of index
26+
str - type of value'''
27+
__slots__ = ()
28+
29+
@abstractmethod
30+
def __array__(self) -> pd.core.series.Series:
31+
pass
32+
33+
34+
class int8(typing_extensions.Protocol):
35+
"""Annotation for int8"""
36+
@abstractmethod
37+
def __int__(self) -> int:
38+
pass
39+
40+
41+
class int16(typing_extensions.Protocol):
42+
"""Annotation for int16"""
43+
@abstractmethod
44+
def __int__(self) -> int:
45+
pass
46+
47+
48+
class int32(typing_extensions.Protocol):
49+
"""Annotation for int32"""
50+
@abstractmethod
51+
def __int__(self) -> int:
52+
pass
53+
54+
55+
class int64(typing_extensions.Protocol):
56+
"""Annotation for int64"""
57+
@abstractmethod
58+
def __int__(self) -> int:
59+
pass
60+
61+
62+
class unint8(typing_extensions.Protocol):
63+
"""Annotation for unsigned int8"""
64+
@abstractmethod
65+
def __int__(self) -> int:
66+
pass
67+
68+
69+
class unint16(typing_extensions.Protocol):
70+
"""Annotation for unsigned int16"""
71+
@abstractmethod
72+
def __int__(self) -> int:
73+
pass
74+
75+
76+
class unint32(typing_extensions.Protocol):
77+
"""Annotation for unsigned int32"""
78+
@abstractmethod
79+
def __int__(self) -> int:
80+
pass
81+
82+
83+
class unint64(typing_extensions.Protocol):
84+
"""Annotation for unsigned int64"""
85+
@abstractmethod
86+
def __int__(self) -> int:
87+
pass
88+
89+
90+
class float32(typing_extensions.Protocol):
91+
"""Annotation for float32"""
92+
@abstractmethod
93+
def __float__(self) -> float:
94+
pass
95+
96+
97+
class float64(typing_extensions.Protocol):
98+
"""Annotation for float32"""
99+
@abstractmethod
100+
def __float__(self) -> float:
101+
pass
102+
103+
104+
number = typing.Union[int, float] # numba's number type
105+
106+
107+
T_int = typing.TypeVar('T_int', int8, int16, int32, int64)
108+
T_float = typing.TypeVar('T_float', float32, float64)
109+
110+
111+
class LiteralType(typing.Generic[T]):
112+
pass
113+
114+
115+
class PreferLiteralType(typing.Generic[T]):
116+
pass
117+
118+
119+
class PreferNonLiteralType(typing.Generic[T]):
120+
pass
121+
122+
123+
L_int = LiteralType[int]
124+
L_float = LiteralType[float]
125+
126+
TL_int = LiteralType[T_int]
127+
TL_float = LiteralType[T_float]

0 commit comments

Comments
 (0)