Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

# system modules 

import inspect 

 

# internal modules 

 

# external modules 

 

 

def get_properties(obj, getter=None, setter=None, deleter=None): 

""" 

Get a mapping of property names to properties from a given object's class 

or a class itself. 

 

Args: 

obj (object): either an object or a class 

getter, setter, deleter (bool, optional): also check whether a 

getter/setter/deleter is defined. The default is no check. 

 

Returns: 

dict : mapping of property names to the properties 

""" 

return dict( 

inspect.getmembers( 

obj if isinstance(obj, type) else type(obj), 

lambda x: ( 

isinstance(x, property) 

and all( 

bool(v) == bool(getattr(x, p)) 

for p, v in { 

"fget": getter, 

"fset": setter, 

"fdel": deleter, 

}.items() 

if v is not None 

) 

), 

) 

) 

 

 

def full_object_path(var): 

""" 

Get the full path string for a given object 

 

Args: 

obj (object): The variable to get the full string from 

 

Returns: 

str : The full object path 

""" 

name = var.__name__ 

module = var.__module__ 

return ( 

name 

if module == "builtins" 

else "{module}.{name}".format(name=name, module=module) 

)