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

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

19 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.""" 

6 

7from __future__ import annotations 

8 

9from astroid import nodes 

10from astroid.brain.brain_numpy_utils import numpy_supports_type_hints 

11from astroid.builder import extract_node 

12from astroid.context import InferenceContext 

13from astroid.inference_tip import inference_tip 

14from astroid.manager import AstroidManager 

15 

16 

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

18 ndarray = """ 

19 class ndarray(object): 

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

21 strides=None, order=None): 

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

23 self.base = None 

24 self.ctypes = None 

25 self.data = None 

26 self.dtype = None 

27 self.flags = None 

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

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

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

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

32 self.itemsize = None 

33 self.nbytes = None 

34 self.ndim = None 

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

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

37 self.size = None 

38 self.strides = None 

39 

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

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

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

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

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

45 def __contains__(self, key): return True 

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

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

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

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

50 def __float__(self): return 0. 

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

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

53 def __getitem__(self, key): return uninferable 

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

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

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

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

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

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

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

61 def __int__(self): return 0 

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

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

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

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

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

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

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

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

70 def __len__(self): return 1 

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

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

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

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

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

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

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

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

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

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

81 def __repr__(self): return str() 

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

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

84 def __str__(self): return str() 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

106 def dump(self, file): return None 

107 def dumps(self): return str() 

108 def fill(self, value): return None 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

138 def tolist(self, ): return [] 

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

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

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

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

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

144 """ 

145 if numpy_supports_type_hints(): 

146 ndarray += """ 

147 @classmethod 

148 def __class_getitem__(cls, value): 

149 return cls 

150 """ 

151 node = extract_node(ndarray) 

152 return node.infer(context=context) 

153 

154 

155def _looks_like_numpy_ndarray(node: nodes.Attribute) -> bool: 

156 return node.attrname == "ndarray" 

157 

158 

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

160 manager.register_transform( 

161 nodes.Attribute, 

162 inference_tip(infer_numpy_ndarray), 

163 _looks_like_numpy_ndarray, 

164 )