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

Commit 90e436e

Browse files
committed
split into several files
1 parent ce0defe commit 90e436e

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

numba_typing/new_types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
__all__ = ['array', 'number_types', 'pandas', 'special']

numba_typing/new_types/array.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import typing
2+
import numpy as np
3+
from abc import abstractmethod
4+
5+
T = typing.TypeVar('T')
6+
S = typing.TypeVar('S')
7+
8+
9+
class Array(typing.Generic[T, S]):
10+
'''Annotation for np.ndarray
11+
Use square brackets to indicate type and dimension
12+
For example: Array[int, typing_extensions.Literal[4]]'''
13+
__slots__ = ()
14+
15+
@abstractmethod
16+
def __array__(self) -> np.ndarray:
17+
pass
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import typing
2+
from abc import abstractmethod
3+
import typing_extensions
4+
5+
6+
class int8(typing_extensions.Protocol):
7+
"""Annotation for int8"""
8+
@abstractmethod
9+
def __int__(self) -> int:
10+
pass
11+
12+
13+
class int16(typing_extensions.Protocol):
14+
"""Annotation for int16"""
15+
@abstractmethod
16+
def __int__(self) -> int:
17+
pass
18+
19+
20+
class int32(typing_extensions.Protocol):
21+
"""Annotation for int32"""
22+
@abstractmethod
23+
def __int__(self) -> int:
24+
pass
25+
26+
27+
class int64(typing_extensions.Protocol):
28+
"""Annotation for int64"""
29+
@abstractmethod
30+
def __int__(self) -> int:
31+
pass
32+
33+
34+
class unint8(typing_extensions.Protocol):
35+
"""Annotation for unsigned int8"""
36+
@abstractmethod
37+
def __int__(self) -> int:
38+
pass
39+
40+
41+
class unint16(typing_extensions.Protocol):
42+
"""Annotation for unsigned int16"""
43+
@abstractmethod
44+
def __int__(self) -> int:
45+
pass
46+
47+
48+
class unint32(typing_extensions.Protocol):
49+
"""Annotation for unsigned int32"""
50+
@abstractmethod
51+
def __int__(self) -> int:
52+
pass
53+
54+
55+
class unint64(typing_extensions.Protocol):
56+
"""Annotation for unsigned int64"""
57+
@abstractmethod
58+
def __int__(self) -> int:
59+
pass
60+
61+
62+
class float32(typing_extensions.Protocol):
63+
"""Annotation for float32"""
64+
@abstractmethod
65+
def __float__(self) -> float:
66+
pass
67+
68+
69+
class float64(typing_extensions.Protocol):
70+
"""Annotation for float32"""
71+
@abstractmethod
72+
def __float__(self) -> float:
73+
pass
74+
75+
76+
number = typing.Union[int, float] # numba's number type
77+
78+
79+
T_int = typing.TypeVar('T_int', int8, int16, int32, int64)
80+
T_float = typing.TypeVar('T_float', float32, float64)

numba_typing/new_types/special.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import typing
2+
import number_types
3+
4+
T = typing.TypeVar('T')
5+
6+
7+
class LiteralType(typing.Generic[T]):
8+
pass
9+
10+
11+
class PreferLiteralType(typing.Generic[T]):
12+
pass
13+
14+
15+
class PreferNonLiteralType(typing.Generic[T]):
16+
pass
17+
18+
19+
L_int = LiteralType[int]
20+
L_float = LiteralType[float]
21+
22+
TL_int = LiteralType[number_types.T_int]
23+
TL_float = LiteralType[number_types.T_float]

0 commit comments

Comments
 (0)