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

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

15 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.core.numeric module.""" 

6 

7import functools 

8 

9from astroid import nodes 

10from astroid.brain.brain_numpy_utils import ( 

11 attribute_name_looks_like_numpy_member, 

12 infer_numpy_attribute, 

13) 

14from astroid.brain.helpers import register_module_extender 

15from astroid.builder import parse 

16from astroid.inference_tip import inference_tip 

17from astroid.manager import AstroidManager 

18from astroid.nodes.node_classes import Attribute 

19 

20 

21def numpy_core_numeric_transform() -> nodes.Module: 

22 return parse( 

23 """ 

24 # different functions defined in numeric.py 

25 import numpy 

26 def zeros_like(a, dtype=None, order='K', subok=True, shape=None): return numpy.ndarray((0, 0)) 

27 def ones_like(a, dtype=None, order='K', subok=True, shape=None): return numpy.ndarray((0, 0)) 

28 def full_like(a, fill_value, dtype=None, order='K', subok=True, shape=None): return numpy.ndarray((0, 0)) 

29 """ 

30 ) 

31 

32 

33METHODS_TO_BE_INFERRED = { 

34 "ones": """def ones(shape, dtype=None, order='C'): 

35 return numpy.ndarray([0, 0])""" 

36} 

37 

38 

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

40 register_module_extender( 

41 manager, "numpy.core.numeric", numpy_core_numeric_transform 

42 ) 

43 

44 manager.register_transform( 

45 Attribute, 

46 inference_tip(functools.partial(infer_numpy_attribute, METHODS_TO_BE_INFERRED)), 

47 functools.partial( 

48 attribute_name_looks_like_numpy_member, 

49 frozenset(METHODS_TO_BE_INFERRED.keys()), 

50 ), 

51 )