Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-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 

21from typing import ( 

22 Any, 

23 Literal, 

24 Sequence, 

25 Type, 

26 Union, 

27 TYPE_CHECKING, 

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"] 

54if TYPE_CHECKING or sys.version_info >= (3, 9): 

55 Dtype = dtype[Union[ 

56 int8, 

57 int16, 

58 int32, 

59 int64, 

60 uint8, 

61 uint16, 

62 uint32, 

63 uint64, 

64 float32, 

65 float64, 

66 ]] 

67else: 

68 Dtype = dtype 

69 

70SupportsBufferProtocol = Any 

71PyCapsule = Any 

72 

73class SupportsDLPack(Protocol): 

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