Skip to content

Commit 00fa703

Browse files
committed
Handle undefined types in annotations in the new function stubs
Except for NestedSequence, which isn't a real type from typing.
1 parent 3cd5eac commit 00fa703

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

array_api_tests/function_stubs/_types.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
array = TypeVar('array')
1111
device = TypeVar('device')
1212
dtype = TypeVar('dtype')
13-
14-
__all__ = ['Literal', 'Optional', 'Tuple', 'Union', 'array', 'device', 'dtype']
13+
SupportsDLPack = TypeVar('SupportsDLPack')
14+
SupportsBufferProtocol = TypeVar('SupportsBufferProtocol')
15+
PyCapsule = TypeVar('PyCapsule')
16+
__all__ = ['Literal', 'Optional', 'Tuple', 'Union', 'array', 'device',
17+
'dtype', 'SupportsDLPack', 'SupportsBufferProtocol', 'PyCapsule']
1518

array_api_tests/function_stubs/array_object.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
from __future__ import annotations
1212

13-
from ._types import Optional, Tuple, Union, array
13+
from enum import IntEnum
14+
from ._types import Optional, PyCapsule, Tuple, Union, array
1415

1516
def __abs__(x: array, /) -> array:
1617
"""
@@ -42,7 +43,7 @@ def __dlpack__(*, stream: Optional[int] = None) -> PyCapsule:
4243
"""
4344
pass
4445

45-
def __dlpack_device__() -> Tuple[enum.IntEnum, int]:
46+
def __dlpack_device__() -> Tuple[IntEnum, int]:
4647
"""
4748
Note: __dlpack_device__ is a method of the array object.
4849
"""

array_api_tests/function_stubs/creation_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from __future__ import annotations
1212

13-
from ._types import Optional, Tuple, Union, array, device, dtype
13+
from ._types import Optional, SupportsBufferProtocol, SupportsDLPack, Tuple, Union, array, device, dtype
1414

1515
def arange(start: Union[int, float], /, *, stop: Optional[Union[int, float]] = None, step: Union[int, float] = 1, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
1616
pass

array_api_tests/function_stubs/data_type_functions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from __future__ import annotations
1212

1313
from ._types import Union, array, dtype
14+
from collections.abc import Sequence
1415

1516
def finfo(type: Union[dtype, array], /) -> finfo:
1617
pass

generate_stubs.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@
3939
4040
from __future__ import annotations
4141
42+
from enum import *
4243
from ._types import *
4344
from .constants import *
45+
from collections.abc import *
4446
'''
4547
# ^ Constants are used in some of the type annotations
4648

@@ -88,8 +90,11 @@
8890
array = TypeVar('array')
8991
device = TypeVar('device')
9092
dtype = TypeVar('dtype')
91-
92-
__all__ = ['Literal', 'Optional', 'Tuple', 'Union', 'array', 'device', 'dtype']
93+
SupportsDLPack = TypeVar('SupportsDLPack')
94+
SupportsBufferProtocol = TypeVar('SupportsBufferProtocol')
95+
PyCapsule = TypeVar('PyCapsule')
96+
__all__ = ['Literal', 'Optional', 'Tuple', 'Union', 'array', 'device',
97+
'dtype', 'SupportsDLPack', 'SupportsBufferProtocol', 'PyCapsule']
9398
9499
'''
95100
def main():
@@ -645,6 +650,7 @@ def clean_type(typ):
645650
typ = typ.replace('\\', '')
646651
typ = typ.replace(' ', '')
647652
typ = typ.replace(',', ', ')
653+
typ = typ.replace('enum.', '')
648654
return typ
649655

650656
def add_annotation(sig, annotation):

0 commit comments

Comments
 (0)