Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.10/site-packages/astroid/brain/brain_numpy_ndarray.py: 83%

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# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 

2# For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE 

3# Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt 

4 

5"""Astroid hooks for numpy ndarray class.""" 

6from __future__ import annotations 

7 

8from astroid.brain.brain_numpy_utils import numpy_supports_type_hints 

9from astroid.builder import extract_node 

10from astroid.context import InferenceContext 

11from astroid.inference_tip import inference_tip 

12from astroid.manager import AstroidManager 

13from astroid.nodes.node_classes import Attribute 

14 

15 

16def infer_numpy_ndarray(node, context: InferenceContext | None = None): 

17 ndarray = """ 

18 class ndarray(object): 

19 def __init__(self, shape, dtype=float, buffer=None, offset=0, 

20 strides=None, order=None): 

21 self.T = numpy.ndarray([0, 0]) 

22 self.base = None 

23 self.ctypes = None 

24 self.data = None 

25 self.dtype = None 

26 self.flags = None 

27 # Should be a numpy.flatiter instance but not available for now 

28 # Putting an array instead so that iteration and indexing are authorized 

29 self.flat = np.ndarray([0, 0]) 

30 self.imag = np.ndarray([0, 0]) 

31 self.itemsize = None 

32 self.nbytes = None 

33 self.ndim = None 

34 self.real = np.ndarray([0, 0]) 

35 self.shape = numpy.ndarray([0, 0]) 

36 self.size = None 

37 self.strides = None 

38 

39 def __abs__(self): return numpy.ndarray([0, 0]) 

40 def __add__(self, value): return numpy.ndarray([0, 0]) 

41 def __and__(self, value): return numpy.ndarray([0, 0]) 

42 def __array__(self, dtype=None): return numpy.ndarray([0, 0]) 

43 def __array_wrap__(self, obj): return numpy.ndarray([0, 0]) 

44 def __contains__(self, key): return True 

45 def __copy__(self): return numpy.ndarray([0, 0]) 

46 def __deepcopy__(self, memo): return numpy.ndarray([0, 0]) 

47 def __divmod__(self, value): return (numpy.ndarray([0, 0]), numpy.ndarray([0, 0])) 

48 def __eq__(self, value): return numpy.ndarray([0, 0]) 

49 def __float__(self): return 0. 

50 def __floordiv__(self): return numpy.ndarray([0, 0]) 

51 def __ge__(self, value): return numpy.ndarray([0, 0]) 

52 def __getitem__(self, key): return uninferable 

53 def __gt__(self, value): return numpy.ndarray([0, 0]) 

54 def __iadd__(self, value): return numpy.ndarray([0, 0]) 

55 def __iand__(self, value): return numpy.ndarray([0, 0]) 

56 def __ifloordiv__(self, value): return numpy.ndarray([0, 0]) 

57 def __ilshift__(self, value): return numpy.ndarray([0, 0]) 

58 def __imod__(self, value): return numpy.ndarray([0, 0]) 

59 def __imul__(self, value): return numpy.ndarray([0, 0]) 

60 def __int__(self): return 0 

61 def __invert__(self): return numpy.ndarray([0, 0]) 

62 def __ior__(self, value): return numpy.ndarray([0, 0]) 

63 def __ipow__(self, value): return numpy.ndarray([0, 0]) 

64 def __irshift__(self, value): return numpy.ndarray([0, 0]) 

65 def __isub__(self, value): return numpy.ndarray([0, 0]) 

66 def __itruediv__(self, value): return numpy.ndarray([0, 0]) 

67 def __ixor__(self, value): return numpy.ndarray([0, 0]) 

68 def __le__(self, value): return numpy.ndarray([0, 0]) 

69 def __len__(self): return 1 

70 def __lshift__(self, value): return numpy.ndarray([0, 0]) 

71 def __lt__(self, value): return numpy.ndarray([0, 0]) 

72 def __matmul__(self, value): return numpy.ndarray([0, 0]) 

73 def __mod__(self, value): return numpy.ndarray([0, 0]) 

74 def __mul__(self, value): return numpy.ndarray([0, 0]) 

75 def __ne__(self, value): return numpy.ndarray([0, 0]) 

76 def __neg__(self): return numpy.ndarray([0, 0]) 

77 def __or__(self, value): return numpy.ndarray([0, 0]) 

78 def __pos__(self): return numpy.ndarray([0, 0]) 

79 def __pow__(self): return numpy.ndarray([0, 0]) 

80 def __repr__(self): return str() 

81 def __rshift__(self): return numpy.ndarray([0, 0]) 

82 def __setitem__(self, key, value): return uninferable 

83 def __str__(self): return str() 

84 def __sub__(self, value): return numpy.ndarray([0, 0]) 

85 def __truediv__(self, value): return numpy.ndarray([0, 0]) 

86 def __xor__(self, value): return numpy.ndarray([0, 0]) 

87 def all(self, axis=None, out=None, keepdims=False): return np.ndarray([0, 0]) 

88 def any(self, axis=None, out=None, keepdims=False): return np.ndarray([0, 0]) 

89 def argmax(self, axis=None, out=None): return np.ndarray([0, 0]) 

90 def argmin(self, axis=None, out=None): return np.ndarray([0, 0]) 

91 def argpartition(self, kth, axis=-1, kind='introselect', order=None): return np.ndarray([0, 0]) 

92 def argsort(self, axis=-1, kind='quicksort', order=None): return np.ndarray([0, 0]) 

93 def astype(self, dtype, order='K', casting='unsafe', subok=True, copy=True): return np.ndarray([0, 0]) 

94 def byteswap(self, inplace=False): return np.ndarray([0, 0]) 

95 def choose(self, choices, out=None, mode='raise'): return np.ndarray([0, 0]) 

96 def clip(self, min=None, max=None, out=None): return np.ndarray([0, 0]) 

97 def compress(self, condition, axis=None, out=None): return np.ndarray([0, 0]) 

98 def conj(self): return np.ndarray([0, 0]) 

99 def conjugate(self): return np.ndarray([0, 0]) 

100 def copy(self, order='C'): return np.ndarray([0, 0]) 

101 def cumprod(self, axis=None, dtype=None, out=None): return np.ndarray([0, 0]) 

102 def cumsum(self, axis=None, dtype=None, out=None): return np.ndarray([0, 0]) 

103 def diagonal(self, offset=0, axis1=0, axis2=1): return np.ndarray([0, 0]) 

104 def dot(self, b, out=None): return np.ndarray([0, 0]) 

105 def dump(self, file): return None 

106 def dumps(self): return str() 

107 def fill(self, value): return None 

108 def flatten(self, order='C'): return np.ndarray([0, 0]) 

109 def getfield(self, dtype, offset=0): return np.ndarray([0, 0]) 

110 def item(self, *args): return uninferable 

111 def itemset(self, *args): return None 

112 def max(self, axis=None, out=None): return np.ndarray([0, 0]) 

113 def mean(self, axis=None, dtype=None, out=None, keepdims=False): return np.ndarray([0, 0]) 

114 def min(self, axis=None, out=None, keepdims=False): return np.ndarray([0, 0]) 

115 def newbyteorder(self, new_order='S'): return np.ndarray([0, 0]) 

116 def nonzero(self): return (1,) 

117 def partition(self, kth, axis=-1, kind='introselect', order=None): return None 

118 def prod(self, axis=None, dtype=None, out=None, keepdims=False): return np.ndarray([0, 0]) 

119 def ptp(self, axis=None, out=None): return np.ndarray([0, 0]) 

120 def put(self, indices, values, mode='raise'): return None 

121 def ravel(self, order='C'): return np.ndarray([0, 0]) 

122 def repeat(self, repeats, axis=None): return np.ndarray([0, 0]) 

123 def reshape(self, shape, order='C'): return np.ndarray([0, 0]) 

124 def resize(self, new_shape, refcheck=True): return None 

125 def round(self, decimals=0, out=None): return np.ndarray([0, 0]) 

126 def searchsorted(self, v, side='left', sorter=None): return np.ndarray([0, 0]) 

127 def setfield(self, val, dtype, offset=0): return None 

128 def setflags(self, write=None, align=None, uic=None): return None 

129 def sort(self, axis=-1, kind='quicksort', order=None): return None 

130 def squeeze(self, axis=None): return np.ndarray([0, 0]) 

131 def std(self, axis=None, dtype=None, out=None, ddof=0, keepdims=False): return np.ndarray([0, 0]) 

132 def sum(self, axis=None, dtype=None, out=None, keepdims=False): return np.ndarray([0, 0]) 

133 def swapaxes(self, axis1, axis2): return np.ndarray([0, 0]) 

134 def take(self, indices, axis=None, out=None, mode='raise'): return np.ndarray([0, 0]) 

135 def tobytes(self, order='C'): return b'' 

136 def tofile(self, fid, sep="", format="%s"): return None 

137 def tolist(self, ): return [] 

138 def tostring(self, order='C'): return b'' 

139 def trace(self, offset=0, axis1=0, axis2=1, dtype=None, out=None): return np.ndarray([0, 0]) 

140 def transpose(self, *axes): return np.ndarray([0, 0]) 

141 def var(self, axis=None, dtype=None, out=None, ddof=0, keepdims=False): return np.ndarray([0, 0]) 

142 def view(self, dtype=None, type=None): return np.ndarray([0, 0]) 

143 """ 

144 if numpy_supports_type_hints(): 

145 ndarray += """ 

146 @classmethod 

147 def __class_getitem__(cls, value): 

148 return cls 

149 """ 

150 node = extract_node(ndarray) 

151 return node.infer(context=context) 

152 

153 

154def _looks_like_numpy_ndarray(node: Attribute) -> bool: 

155 return node.attrname == "ndarray" 

156 

157 

158def register(manager: AstroidManager) -> None: 

159 manager.register_transform( 

160 Attribute, 

161 inference_tip(infer_numpy_ndarray), 

162 _looks_like_numpy_ndarray, 

163 )