-
-
Notifications
You must be signed in to change notification settings - Fork 32
Add basic stubs for some class attributes #9
Changes from all commits
d9063b9
f6efbfd
cf16064
b814fac
59bd6bc
5bffb72
eac85ff
d6c586c
3cc8475
c84c9bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.mypy_cache |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
language: python | ||
python: 3.6 | ||
|
||
notifications: | ||
email: false | ||
|
||
install: | ||
- pip install -r test-requirements.txt | ||
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then pip install flake8-pyi==17.3.0; fi | ||
|
||
script: | ||
- flake8 | ||
- MYPYPATH="." mypy tests/test_simple.py | ||
|
||
cache: | ||
directories: | ||
- "$HOME/.cache/pip" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,188 @@ | ||
# very simple, just enough to start running tests | ||
# | ||
import builtins | ||
from typing import Any, Mapping, List, Optional, Tuple, Union | ||
|
||
class ndarray: pass | ||
from numpy.core._internal import _ctypes | ||
|
||
_Shape = Tuple[int, ...] | ||
|
||
class dtype: | ||
names: Optional[Tuple[str, ...]] | ||
|
||
@property | ||
def alignment(self) -> int: ... | ||
|
||
@property | ||
def base(self) -> dtype: ... | ||
|
||
@property | ||
def byteorder(self) -> str: ... | ||
|
||
@property | ||
def char(self) -> str: ... | ||
|
||
@property | ||
def descr(self) -> List[Union[ | ||
Tuple[str, str], | ||
Tuple[str, str, _Shape]]]: ... | ||
|
||
@property | ||
def fields(self) -> Optional[Mapping[ | ||
str, | ||
Union[Tuple[dtype, int], | ||
Tuple[dtype, int, Any]]]]: ... | ||
|
||
@property | ||
def flags(self) -> int: ... | ||
|
||
@property | ||
def hasobject(self) -> bool: ... | ||
|
||
@property | ||
def isbuiltin(self) -> int: ... | ||
|
||
@property | ||
def isnative(self) -> bool: ... | ||
|
||
@property | ||
def isalignedstruct(self) -> bool: ... | ||
|
||
@property | ||
def itemsize(self) -> int: ... | ||
|
||
@property | ||
def kind(self) -> str: ... | ||
|
||
@property | ||
def metadata(self) -> Optional[Mapping[str, Any]]: ... | ||
|
||
@property | ||
def name(self) -> str: ... | ||
|
||
@property | ||
def num(self) -> int: ... | ||
|
||
@property | ||
def shape(self) -> _Shape: ... | ||
|
||
@property | ||
def ndim(self) -> int: ... | ||
|
||
@property | ||
def subdtype(self) -> Optional[Tuple[dtype, _Shape]]: ... | ||
|
||
def newbyteorder(self, new_order: str = ...) -> dtype: ... | ||
|
||
# Leave str and type for end to avoid having to use `builtins.str` | ||
# everywhere. See https://github.com/python/mypy/issues/3775 | ||
@property | ||
def str(self) -> builtins.str: ... | ||
|
||
@property | ||
def type(self) -> builtins.type: ... | ||
|
||
|
||
_dtype_class = dtype # for ndarray type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this have a duplicate name? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Otherwise mypy gets confused when you to type the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you fix it with an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know exactly how mypy handles circular imports, but I suspect that importing a module from itself would not work. |
||
|
||
|
||
class _flagsobj: | ||
aligned: bool | ||
updateifcopy: bool | ||
writeable: bool | ||
writebackifcopy: bool | ||
|
||
@property | ||
def behaved(self) -> bool: ... | ||
|
||
@property | ||
def c_contiguous(self) -> bool: ... | ||
|
||
@property | ||
def carray(self) -> bool: ... | ||
|
||
@property | ||
def contiguous(self) -> bool: ... | ||
|
||
@property | ||
def f_contiguous(self) -> bool: ... | ||
|
||
@property | ||
def farray(self) -> bool: ... | ||
|
||
@property | ||
def fnc(self) -> bool: ... | ||
|
||
@property | ||
def forc(self) -> bool: ... | ||
|
||
@property | ||
def fortran(self) -> bool: ... | ||
|
||
@property | ||
def num(self) -> int: ... | ||
|
||
@property | ||
def owndata(self) -> bool: ... | ||
|
||
def __getitem__(self, key: str) -> bool: ... | ||
def __setitem__(self, key: str, value: bool) -> None: ... | ||
|
||
|
||
class flatiter: | ||
@property | ||
def base(self) -> ndarray: ... | ||
|
||
@property | ||
def coords(self) -> _Shape: ... | ||
|
||
@property | ||
def index(self) -> int: ... | ||
|
||
def copy(self) -> ndarray: ... | ||
def __iter__(self) -> flatiter: ... | ||
def __next__(self) -> Any: ... | ||
|
||
|
||
class ndarray: | ||
dtype: _dtype_class | ||
imag: ndarray | ||
real: ndarray | ||
shape: _Shape | ||
strides: Tuple[int, ...] | ||
|
||
@property | ||
def T(self) -> ndarray: ... | ||
|
||
@property | ||
def base(self) -> Optional[ndarray]: ... | ||
|
||
@property | ||
def ctypes(self) -> _ctypes: ... | ||
|
||
@property | ||
def data(self) -> memoryview: ... | ||
|
||
@property | ||
def flags(self) -> _flagsobj: ... | ||
|
||
@property | ||
def flat(self) -> flatiter: ... | ||
|
||
@property | ||
def size(self) -> int: ... | ||
|
||
@property | ||
def itemsize(self) -> int: ... | ||
|
||
@property | ||
def nbytes(self) -> int: ... | ||
|
||
@property | ||
def ndim(self) -> int: ... | ||
|
||
def __getattr__(self, name) -> Any: ... | ||
|
||
class dtype: pass | ||
|
||
def array( | ||
object: object, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from typing import Any | ||
|
||
# TODO: add better annotations when ctypes is stubbed out | ||
|
||
class _ctypes: | ||
@property | ||
def data(self) -> int: ... | ||
|
||
@property | ||
def shape(self) -> Any: ... | ||
|
||
@property | ||
def strides(self) -> Any: ... | ||
|
||
def data_as(self, obj: Any) -> Any: ... | ||
def shape_as(self, obj: Any) -> Any: ... | ||
def strides_as(self, obj: Any) -> Any: ... | ||
def get_data(self) -> int: ... | ||
def get_shape(self) -> Any: ... | ||
def get_strides(self) -> Any: ... | ||
def get_as_parameter(self) -> Any: ... |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Ignore the following errors (for stubs): | ||
# E301 expected 1 blank line, found 0 | ||
# E302 expected 2 blank lines, found 1 | ||
# E305 expected 2 blank lines after class or function definition, found 1 | ||
# E701 multiple statements on one line (colon) | ||
# E704 multiple statements on one line (def) | ||
|
||
[flake8] | ||
ignore = E301, E302, E305, E701, E704 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
flake8==3.3.0 | ||
|
||
mypy==0.560.0 |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More specifically, we could define the
np.generic
class and switch this toType[generic]
(but this is also fine for now -- certainly let's save defining the full NumPy scalar type hierarchy for later).