Coverage for /usr/lib/python3/dist-packages/sympy/utilities/source.py: 15%

13 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-14 15:55 +0200

1""" 

2This module adds several functions for interactive source code inspection. 

3""" 

4 

5 

6def get_class(lookup_view): 

7 """ 

8 Convert a string version of a class name to the object. 

9 

10 For example, get_class('sympy.core.Basic') will return 

11 class Basic located in module sympy.core 

12 """ 

13 if isinstance(lookup_view, str): 

14 mod_name, func_name = get_mod_func(lookup_view) 

15 if func_name != '': 

16 lookup_view = getattr( 

17 __import__(mod_name, {}, {}, ['*']), func_name) 

18 if not callable(lookup_view): 

19 raise AttributeError( 

20 "'%s.%s' is not a callable." % (mod_name, func_name)) 

21 return lookup_view 

22 

23 

24def get_mod_func(callback): 

25 """ 

26 splits the string path to a class into a string path to the module 

27 and the name of the class. 

28 

29 Examples 

30 ======== 

31 

32 >>> from sympy.utilities.source import get_mod_func 

33 >>> get_mod_func('sympy.core.basic.Basic') 

34 ('sympy.core.basic', 'Basic') 

35 

36 """ 

37 dot = callback.rfind('.') 

38 if dot == -1: 

39 return callback, '' 

40 return callback[:dot], callback[dot + 1:]