This repository was archived by the owner on Jun 10, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 31
MAINT: Fix issue 77: Don't allow initializing generic
#80
Closed
Closed
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9749fbc
Addressed https://github.com/numpy/numpy-stubs/issues/77
ee18c33
FIXED: ``np.void`` also accepts booleans
4abf55b
Added *args & **kwargs to ``generic.__init__()``
56b8c60
Disable a test on WIndows (for now)
b4e3e05
Implemented https://github.com/numpy/numpy-stubs/pull/80#discussion_r…
7c58c3d
Travis is not running; force a rerun
2e1f7a3
Run black one more time
b71ffd2
MAINT: remove ABCMeta import
person142 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import builtins | ||
import sys | ||
import datetime as dt | ||
from abc import abstractmethod, ABCMeta | ||
|
||
from numpy.core._internal import _ctypes | ||
from numpy.typing import ArrayLike, DtypeLike, _Shape, _ShapeLike | ||
|
@@ -359,22 +360,33 @@ class ndarray(_ArrayOrScalarCommon, Iterable, Sized, Container): | |
def __contains__(self, key) -> bool: ... | ||
def __index__(self) -> int: ... | ||
|
||
# NOTE: while `np.generic` is not technically an instance of `ABCMeta`, | ||
# the `@abstractmethod` decorator is herein used to (forcefully) deny | ||
# the creation of `np.generic` instances. | ||
# The `# type: ignore` comments are necessary to silence mypy errors regarding | ||
# the missing `ABCMeta` metaclass. | ||
|
||
# See https://github.com/numpy/numpy-stubs/pull/80 for more details. | ||
|
||
class generic(_ArrayOrScalarCommon): | ||
def __init__(self, value: Any = ...) -> None: ... | ||
@abstractmethod | ||
def __init__(self, *args: Any, **kwargs: Any) -> None: ... | ||
@property | ||
def base(self) -> None: ... | ||
|
||
class _real_generic(generic): | ||
class _real_generic(generic): # type: ignore | ||
@property | ||
def real(self: _ArraySelf) -> _ArraySelf: ... | ||
@property | ||
def imag(self: _ArraySelf) -> _ArraySelf: ... | ||
|
||
class number(generic): | ||
def __init__(self, value: Union[SupportsInt, SupportsFloat] = ...) -> None: ... | ||
class number(generic): ... # type: ignore | ||
|
||
class bool_(_real_generic): | ||
def __init__(self, value: object = ...) -> None: ... | ||
|
||
class bool_(_real_generic): ... | ||
class object_(generic): ... | ||
class object_(generic): | ||
def __init__(self, value: object = ...) -> None: ... | ||
|
||
class datetime64: | ||
@overload | ||
|
@@ -386,8 +398,8 @@ class datetime64: | |
def __add__(self, other: Union[timedelta64, int]) -> datetime64: ... | ||
def __sub__(self, other: Union[timedelta64, datetime64, int]) -> timedelta64: ... | ||
|
||
class integer(number, _real_generic): ... | ||
class signedinteger(integer): ... | ||
class integer(number, _real_generic): ... # type: ignore | ||
class signedinteger(integer): ... # type: ignore | ||
|
||
class int8(signedinteger): | ||
def __init__(self, value: SupportsInt = ...) -> None: ... | ||
|
@@ -419,7 +431,7 @@ class timedelta64(signedinteger): | |
def __truediv__(self, other: float) -> timedelta64: ... | ||
def __mod__(self, other: timedelta64) -> timedelta64: ... | ||
|
||
class unsignedinteger(integer): ... | ||
class unsignedinteger(integer): ... # type: ignore | ||
|
||
class uint8(unsignedinteger): | ||
def __init__(self, value: SupportsInt = ...) -> None: ... | ||
|
@@ -433,34 +445,60 @@ class uint32(unsignedinteger): | |
class uint64(unsignedinteger): | ||
def __init__(self, value: SupportsInt = ...) -> None: ... | ||
|
||
class inexact(number): ... | ||
class floating(inexact, _real_generic): ... | ||
class float16(floating): ... | ||
class float32(floating): ... | ||
class float64(floating): ... | ||
class inexact(number): ... # type: ignore | ||
class floating(inexact, _real_generic): ... # type: ignore | ||
|
||
class complexfloating(inexact): | ||
def __init__( | ||
self, value: Union[SupportsInt, SupportsFloat, SupportsComplex, complex] = ... | ||
) -> None: ... | ||
class float16(floating): | ||
def __init__(self, value: SupportsFloat = ...) -> None: ... | ||
|
||
class float32(floating): | ||
def __init__(self, value: SupportsFloat = ...) -> None: ... | ||
|
||
class float64(floating): | ||
def __init__(self, value: SupportsFloat = ...) -> None: ... | ||
|
||
class complexfloating(inexact): ... # type: ignore | ||
|
||
class complex64(complexfloating): | ||
def __init__( | ||
self, value: Union[SupportsInt, SupportsFloat, SupportsComplex] = ... | ||
) -> None: ... | ||
@property | ||
def real(self) -> float32: ... | ||
@property | ||
def imag(self) -> float32: ... | ||
|
||
class complex128(complexfloating): | ||
def __init__( | ||
self, value: Union[SupportsInt, SupportsFloat, SupportsComplex] = ... | ||
) -> None: ... | ||
@property | ||
def real(self) -> float64: ... | ||
@property | ||
def imag(self) -> float64: ... | ||
|
||
class flexible(_real_generic): ... | ||
class void(flexible): ... | ||
class character(_real_generic): ... | ||
class bytes_(character): ... | ||
class str_(character): ... | ||
class flexible(_real_generic): ... # type: ignore | ||
|
||
class void(flexible): | ||
def __init__(self, value: Union[int, integer, bool_, bytes, bytes_]): ... | ||
|
||
class character(_real_generic): ... # type: ignore | ||
|
||
class bytes_(character): | ||
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. So contrary to its >>> import numpy as np
>>> np.bytes_(0)
b''
>>> np.bytes_(None)
b'None' # Equivalent to np.bytes_(str(None))
>>> class Test:
... pass
>>> np.bytes_(Test)
b"<class '__main__.Test'>"
>>> np.bytes_(Test())
b'<__main__.Test object at ...>' |
||
@overload | ||
def __init__(self, value: object = ...) -> None: ... | ||
@overload | ||
def __init__( | ||
self, value: object, encoding: str = ..., errors: str = ... | ||
) -> None: ... | ||
|
||
class str_(character): | ||
@overload | ||
def __init__(self, value: object = ...) -> None: ... | ||
@overload | ||
def __init__( | ||
self, value: object, encoding: str = ..., errors: str = ... | ||
) -> None: ... | ||
|
||
# TODO(alan): Platform dependent types | ||
# longcomplex, longdouble, longfloat | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Forgot to remove the
ABCMeta
import I think?