Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.9/dist-packages/numpy/array_api/_typing.py: 0%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

18 statements  

1""" 

2This file defines the types for type annotations. 

3 

4These names aren't part of the module namespace, but they are used in the 

5annotations in the function signatures. The functions in the module are only 

6valid for inputs that match the given type annotations. 

7""" 

8 

9from __future__ import annotations 

10 

11__all__ = [ 

12 "Array", 

13 "Device", 

14 "Dtype", 

15 "SupportsDLPack", 

16 "SupportsBufferProtocol", 

17 "PyCapsule", 

18] 

19 

20import sys 

21 

22from typing import ( 

23 Any, 

24 Literal, 

25 Sequence, 

26 Type, 

27 Union, 

28 TypeVar, 

29 Protocol, 

30) 

31 

32from ._array_object import Array 

33from numpy import ( 

34 dtype, 

35 int8, 

36 int16, 

37 int32, 

38 int64, 

39 uint8, 

40 uint16, 

41 uint32, 

42 uint64, 

43 float32, 

44 float64, 

45) 

46 

47_T_co = TypeVar("_T_co", covariant=True) 

48 

49class NestedSequence(Protocol[_T_co]): 

50 def __getitem__(self, key: int, /) -> _T_co | NestedSequence[_T_co]: ... 

51 def __len__(self, /) -> int: ... 

52 

53Device = Literal["cpu"] 

54 

55Dtype = dtype[Union[ 

56 int8, 

57 int16, 

58 int32, 

59 int64, 

60 uint8, 

61 uint16, 

62 uint32, 

63 uint64, 

64 float32, 

65 float64, 

66]] 

67 

68if sys.version_info >= (3, 12): 

69 from collections.abc import Buffer as SupportsBufferProtocol 

70else: 

71 SupportsBufferProtocol = Any 

72 

73PyCapsule = Any 

74 

75class SupportsDLPack(Protocol): 

76 def __dlpack__(self, /, *, stream: None = ...) -> PyCapsule: ...