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

Commit 5bffb72

Browse files
committed
Make attributes read-only properties
1 parent 59bd6bc commit 5bffb72

File tree

1 file changed

+140
-48
lines changed

1 file changed

+140
-48
lines changed

numpy/__init__.pyi

Lines changed: 140 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,85 +6,177 @@ from typing import Any, Mapping, List, Optional, Tuple, Union
66
from numpy.core._internal import _ctypes
77

88
class dtype:
9-
alignment: int
10-
byteorder: str
11-
char: str
12-
descr: List[Union[Tuple[str, str], Tuple[str, str, Tuple[int, ...]]]]
13-
fields: Optional[Mapping[str, Union[Tuple[dtype, int], Tuple[dtype, int, str]]]]
14-
flags: int
15-
hasobject: bool
16-
isbuiltin: int
17-
isnative: bool
18-
isalignedstruct: bool
19-
itemsize: int
20-
kind: str
21-
name: str
229
names: Optional[Tuple[str, ...]]
23-
num: int
24-
shape: Tuple[int, ...]
25-
ndim: int
26-
subdtype: Optional[Tuple[dtype, Tuple[int, ...]]]
10+
updateifcopy: bool
11+
writeable: bool
12+
writebackifcopy: bool
13+
14+
@property
15+
def alignment(self) -> int: ...
2716

17+
@property
18+
def base(self) -> dtype: ...
2819

29-
def newbyteorder(self, new_order: str = ...): dtype
20+
@property
21+
def byteorder(self) -> str: ...
3022

31-
str: builtins.str
32-
type: builtins.type
23+
@property
24+
def char(self) -> str: ...
3325

3426
@property
35-
def base(self) -> dtype: ...
27+
def descr(self) -> List[Union[
28+
Tuple[str, str],
29+
Tuple[str, str, Tuple[int, ...]]]]: ...
30+
31+
@property
32+
def fields(self) -> Optional[Mapping[
33+
str,
34+
Union[Tuple[dtype, int],
35+
Tuple[dtype, int, Any]]]]: ...
36+
37+
@property
38+
def flags(self) -> int: ...
39+
40+
@property
41+
def hasobject(self) -> bool: ...
42+
43+
@property
44+
def isbuiltin(self) -> int: ...
45+
46+
@property
47+
def isnative(self) -> bool: ...
48+
49+
@property
50+
def isalignedstruct(self) -> bool: ...
51+
52+
@property
53+
def itemsize(self) -> int: ...
54+
55+
@property
56+
def kind(self) -> str: ...
57+
58+
@property
59+
def name(self) -> str: ...
60+
61+
@property
62+
def num(self) -> int: ...
63+
64+
@property
65+
def shape(self) -> Tuple[int, ...]: ...
66+
67+
@property
68+
def ndim(self) -> int: ...
69+
70+
@property
71+
def subdtype(self) -> Optional[Tuple[dtype, Tuple[int, ...]]]: ...
72+
73+
def newbyteorder(self, new_order: str = ...) -> dtype: ...
74+
75+
# Leave str and type for end to avoid having to use `builtins.str`
76+
# everywhere. See https://github.com/python/mypy/issues/3775
77+
@property
78+
def str(self) -> builtins.str: ...
79+
80+
@property
81+
def type(self) -> builtins.type: ...
3682

3783

3884
_dtype_class = dtype # for ndarray type
3985

4086

4187
class _flagsobj:
4288
aligned: bool
43-
behaved: bool
44-
c_contiguous: bool
45-
carray: bool
46-
contiguous: bool
47-
f_contiguous: bool
48-
farray: bool
49-
fnc: bool
50-
forc: bool
51-
fortran: bool
52-
num: bool
53-
owndata: bool
54-
updateifcopy: bool
55-
writeable: bool
56-
writebackifcopy: bool
89+
90+
@property
91+
def behaved(self) -> bool: ...
92+
93+
@property
94+
def c_contiguous(self) -> bool: ...
95+
96+
@property
97+
def carray(self) -> bool: ...
98+
99+
@property
100+
def contiguous(self) -> bool: ...
101+
102+
@property
103+
def f_contiguous(self) -> bool: ...
104+
105+
@property
106+
def farray(self) -> bool: ...
107+
108+
@property
109+
def fnc(self) -> bool: ...
110+
111+
@property
112+
def forc(self) -> bool: ...
113+
114+
@property
115+
def fortran(self) -> bool: ...
116+
117+
@property
118+
def num(self) -> int: ...
119+
120+
@property
121+
def owndata(self) -> bool: ...
57122

58123
def __getitem__(self, key: str) -> bool: ...
59124
def __setitem__(self, key: str, value: bool) -> None: ...
60125

61126

62127
class flatiter:
63-
base: ndarray
64-
coords: Tuple[int, ...]
65-
index: int
128+
@property
129+
def base(self) -> ndarray: ...
130+
131+
@property
132+
def coords(self) -> Tuple[int, ...]: ...
133+
134+
@property
135+
def index(self) -> int: ...
66136

67137
def copy(self) -> ndarray: ...
68138
def __iter__(self) -> flatiter: ...
69139
def __next__(self) -> Any: ...
70140

71141

72142
class ndarray:
73-
T: ndarray
74-
data: memoryview
75143
dtype: _dtype_class
76-
flags: _flagsobj
77-
flat: flatiter
78144
imag: ndarray
79145
real: ndarray
80-
size: int
81-
itemsize: int
82-
nbytes: int
83-
ndim: int
84146
shape: Tuple[int, ...]
85147
strides: Tuple[int, ...]
86-
ctypes: _ctypes
87-
base: Optional[ndarray]
148+
149+
@property
150+
def T(self) -> ndarray: ...
151+
152+
@property
153+
def dat(self) -> memoryview: ...
154+
155+
@property
156+
def flags(self) -> _flagsobj: ...
157+
158+
@property
159+
def flat(self) -> flatiter: ...
160+
161+
@property
162+
def size(self) -> int: ...
163+
164+
@property
165+
def itemsize(self) -> int: ...
166+
167+
@property
168+
def nbytes(self) -> int: ...
169+
170+
@property
171+
def ndim(self) -> int: ...
172+
173+
@property
174+
def ctypes(self) -> _ctypes: ...
175+
176+
@property
177+
def base(self) -> Optional[ndarray]: ...
178+
179+
def __getattr__(self, name) -> Any: ...
88180

89181

90182
def array(

0 commit comments

Comments
 (0)