50 if not names and hasattr(var, "__members__"): |
50 if not names and hasattr(var, "__members__"): |
51 names = var.__members__ |
51 names = var.__members__ |
52 |
52 |
53 d = {} |
53 d = {} |
54 for name in names: |
54 for name in names: |
55 try: |
55 with contextlib.suppress(Exception): |
56 attribute = getattr(var, name) |
56 attribute = getattr(var, name) |
57 d[name] = attribute |
57 d[name] = attribute |
58 except Exception: # secok |
|
59 pass # if we can't get it, simply ignore it |
|
60 |
58 |
61 return d |
59 return d |
62 |
60 |
63 |
61 |
64 ############################################################ |
62 ############################################################ |
84 if not names and hasattr(var, "__members__"): |
82 if not names and hasattr(var, "__members__"): |
85 names = var.__members__ |
83 names = var.__members__ |
86 |
84 |
87 d = {} |
85 d = {} |
88 for name in names: |
86 for name in names: |
89 try: |
87 with contextlib.suppress(Exception): |
90 attribute = getattr(var, name) |
88 attribute = getattr(var, name) |
91 d[name] = attribute |
89 d[name] = attribute |
92 except Exception: # secok |
|
93 pass # if we can't get it, simply ignore it |
|
94 |
90 |
95 yield -1, d |
91 yield -1, d |
96 while True: |
92 while True: |
97 yield -2, {} |
93 yield -2, {} |
98 |
94 |
656 ] |
652 ] |
657 |
653 |
658 with contextlib.suppress(Exception): |
654 with contextlib.suppress(Exception): |
659 _TypeMap.append((long, None)) # __IGNORE_WARNING__ |
655 _TypeMap.append((long, None)) # __IGNORE_WARNING__ |
660 |
656 |
661 try: |
657 with contextlib.suppress(ImportError): |
662 import array |
658 import array |
663 _TypeMap.append((array.array, arrayResolver)) |
659 _TypeMap.append((array.array, arrayResolver)) |
664 except ImportError: |
660 # array.array may not be available |
665 pass # array.array may not be available |
661 |
666 |
662 with contextlib.suppress(ImportError): |
667 try: |
|
668 import numpy |
663 import numpy |
669 _TypeMap.append((numpy.ndarray, ndarrayResolver)) |
664 _TypeMap.append((numpy.ndarray, ndarrayResolver)) |
670 except ImportError: |
665 # numpy may not be installed |
671 pass # numpy may not be installed |
666 |
672 |
667 with contextlib.suppress(ImportError): |
673 try: |
|
674 from django.utils.datastructures import MultiValueDict |
668 from django.utils.datastructures import MultiValueDict |
675 # it should go before dict |
669 # it should go before dict |
676 _TypeMap.insert(0, (MultiValueDict, multiValueDictResolver)) |
670 _TypeMap.insert(0, (MultiValueDict, multiValueDictResolver)) |
677 except ImportError: |
671 # django may not be installed |
678 pass # django may not be installed |
672 |
679 |
673 with contextlib.suppress(ImportError): |
680 try: |
|
681 from collections.abc import ItemsView, KeysView, ValuesView |
674 from collections.abc import ItemsView, KeysView, ValuesView |
682 _TypeMap.append((ItemsView, dictViewResolver)) |
675 _TypeMap.append((ItemsView, dictViewResolver)) |
683 _TypeMap.append((KeysView, dictViewResolver)) |
676 _TypeMap.append((KeysView, dictViewResolver)) |
684 _TypeMap.append((ValuesView, dictViewResolver)) |
677 _TypeMap.append((ValuesView, dictViewResolver)) |
685 except ImportError: |
678 # not available on all Python versions |
686 pass # not available on all Python versions |
|
687 |
679 |
688 |
680 |
689 def getType(obj): |
681 def getType(obj): |
690 """ |
682 """ |
691 Public method to get the type information for an object. |
683 Public method to get the type information for an object. |