10000 Add basic stubs for some class attributes (#9) · numpy/numpy-stubs@6166b30 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.

Commit 6166b30

Browse files
Alan Dushoyer
authored andcommitted
Add basic stubs for some class attributes (#9)
* Add some typehints * Add ctypes typehints * Add stubs for dtype * Setup Travis and correct setup.py (#8) * Replace tab in setup.py with spaces * Add Travis * Add flake8 config to pass tests * Use `-` instead of `_` See python/peps#568 * Add Travis badge to README * Use numpy 1.14.0 * Fix some type annotations * Make attributes read-only properties * Add metadata property * Move flags into flagobj * Add _Shape type alias * Alphabetize properties
1 parent 2f2f9b1 commit 6166b30

File tree

3 files changed

+203
-2
lines changed

3 files changed

+203
-2
lines changed

numpy/__init__.pyi

Lines changed: 182 additions & 2 deletions
< 57AE td data-grid-cell-id="diff-db8483d86d7214c860f5426db5b4f219d991f60ea325f49040e6e06d5278bb03-3-113-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionNum-bgColor, var(--diffBlob-addition-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,188 @@
11
# very simple, just enough to start running tests
2+
#
3+
import builtins
4+
from typing import Any, Mapping, List, Optional, Tuple, Union
25

3-
class ndarray: pass
6+
from numpy.core._internal import _ctypes
7+
8+
_Shape = Tuple[int, ...]
9+
10+
class dtype:
11+
names: Optional[Tuple[str, ...]]
12+
13+
@property
14+
def alignment(self) -> int: ...
15+
16+
@property
17+
def base(self) -> dtype: ...
18+
19+
@property
20+
def byteorder(self) -> str: ...
21+
22+
@property
23+
def char(self) -> str: ...
24+
25+
@property
26+
def descr(self) -> List[Union[
27+
Tuple[str, str],
28+
Tuple[str, str, _Shape]]]: ...
29+
30+
@property
31+
def fields(self) -> Optional[Mapping[
32+
str,
33+
Union[Tuple[dtype, int],
34+
Tuple[dtype, int, Any]]]]: ...
35+
36+
@property
37+
def flags(self) -> int: ...
38+
39+
@property
40+
def hasobject(self) -> bool: ...
41+
42+
@property
43+
def isbuiltin(self) -> int: ...
44+
45+
@property
46+
def isnative(self) -> bool: ...
47+
48+
@property
49+
def isalignedstruct(self) -> bool: ...
50+
51+
@property
52+
def itemsize(self) -> int: ...
53+
54+
@property
55+
def kind(self) -> str: ...
56+
57+
@property
58+
def metadata(self) -> Optional[Mapping[str, Any]]: ...
59+
60+
@property
61+
def name(self) -> str: ...
62+
63+
@property
64+
def num(self) -> int: ...
65+
66+
@property
67+
def shape(self) -> _Shape: ...
68+
69+
@property
70+
def ndim(self) -> int: ...
71+
72+
@property
73+
def subdtype(self) -> Optional[Tuple[dtype, _Shape]]: ...
74+
75+
def newbyteorder(self, new_order: str = ...) -> dtype: ...
76+
77+
# Leave str and type for end to avoid having to use `builtins.str`
78+
# everywhere. See https://github.com/python/mypy/issues/3775
79+
@property
80+
def str(self) -> builtins.str: ...
81+
82+
@property
83+
def type(self) -> builtins.type: ...
84+
85+
86+
_dtype_class = dtype # for ndarray type
87+
88+
89+
class _flagsobj:
90+
aligned: bool
91+
updateifcopy: bool
92+
writeable: bool
93+
writebackifcopy: bool
94+
95+
@property
96+
def behaved(self) -> bool: ...
97+
98+
@property
99+
def c_contiguous(self) -> bool: ...
100+
101+
@property
102+
def carray(self) -> bool: ...
103+
104+
@property
105+
def contiguous(self) -> bool: ...
106+
107+
@property
108+
def f_contiguous(self) -> bool: ...
109+
110+
@property
111+
def farray(self) -> bool: ...
112+
113+
@property
114+
def fnc(self) -> bool: ...
115+
116+
@property
117+
def forc(self) -> bool: ...
118+
119+
@property
120+
def fortran(self) -> bool: ...
121+
122+
@property
123+
def num(self) -> int: ...
124+
125+
@property
126+
def owndata(self) -> bool: ...
127+
128+
def __getitem__(self, key: str) -> bool: ...
129+
def __setitem__(self, key: str, value: bool) -> None: ...
130+
131+
132+
class flatiter:
133+
@property
134+
def base(self) -> ndarray: ...
135+
136+
@property
137+
def coords(self) -> _Shape: ...
138+
139+
@property
140+
def index(self) -> int: ...
141+
142+
def copy(self) -> ndarray: ...
143+
def __iter__(self) -> flatiter: ...
144+
def __next__(self) -> Any: ...
145+
146+
147+
class ndarray:
148+
dtype: _dtype_class
149+
imag: ndarray
150+
real: ndarray
151+
shape: _Shape
152+
strides: Tuple[int, ...]
153+
154+
@property
155+
def T(self) -> ndarray: ...
156+
157+
@property
158+
def base(self) -> Optional[ndarray]: ...
159+
160+
@property
161+
def ctypes(self) -> _ctypes: ...
162+
163+
@property
164+
def data(self) -> memoryview: ...
165+
166+
@property
167+
def flags(self) -> _flagsobj: ...
168+
169+
@property
170+
def flat(self) -> flatiter: ...
171+
172+
@property
173+
def size(self) -> int: ...
174+
175+
@property
176+
def itemsize(self) -> int: ...
177+
178+
@property
179+
def nbytes(self) -> int: ...
180+
181+
@property
182+
def ndim(self) -> int: ...
183+
184+
def __getattr__(self, name) -> Any: ...
4185

5-
class dtype: pass
6186

7187
def array(
8188
object: object,

numpy/core/__init__.pyi

Whitespace-only changes.

numpy/core/_internal.pyi

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from typing import Any
2+
3+
# TODO: add better annotations when ctypes is stubbed out
4+
5+
class _ctypes:
8EBC 6+
@property
7+
def data(self) -> int: ...
8+
9+
@property
10+
def shape(self) -> Any: ...
11+
12+
@property
13+
def strides(self) -> Any: ...
14+
15+
def data_as(self, obj: Any) -> Any: ...
16+
def shape_as(self, obj: Any) -> Any: ...
17+
def strides_as(self, obj: Any) -> Any: ...
18+
def get_data(self) -> int: ...
19+
def get_shape(self) -> Any: ...
20+
def get_strides(self) -> Any: ...
21+
def get_as_parameter(self) -> Any: ...

0 commit comments

Comments
 (0)
0