Show More
@@ -1445,8 +1445,20 b' class InteractiveShell(SingletonConfigurable):' | |||||
1445 | ismagic = True |
|
1445 | ismagic = True | |
1446 | isalias = isinstance(obj, Alias) |
|
1446 | isalias = isinstance(obj, Alias) | |
1447 |
|
1447 | |||
1448 | return {'found':found, 'obj':obj, 'namespace':ospace, |
|
1448 | # Last try: special-case some literals like '', [], {}, etc: | |
1449 | 'ismagic':ismagic, 'isalias':isalias, 'parent':parent} |
|
1449 | if not found and oname_head in ["''",'""','[]','{}','()']: | |
|
1450 | obj = eval(oname_head) | |||
|
1451 | found = True | |||
|
1452 | ospace = 'Interactive' | |||
|
1453 | ||||
|
1454 | return { | |||
|
1455 | 'obj':obj, | |||
|
1456 | 'found':found, | |||
|
1457 | 'parent':parent, | |||
|
1458 | 'ismagic':ismagic, | |||
|
1459 | 'isalias':isalias, | |||
|
1460 | 'namespace':ospace | |||
|
1461 | } | |||
1450 |
|
1462 | |||
1451 | @staticmethod |
|
1463 | @staticmethod | |
1452 | def _getattr_property(obj, attrname): |
|
1464 | def _getattr_property(obj, attrname): | |
@@ -2550,7 +2562,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
2550 | where.update( |
|
2562 | where.update( | |
2551 | runpy.run_module(str(mod_name), run_name="__main__", |
|
2563 | runpy.run_module(str(mod_name), run_name="__main__", | |
2552 | alter_sys=True) |
|
2564 | alter_sys=True) | |
2553 | ) |
|
2565 | ) | |
2554 | except SystemExit as status: |
|
2566 | except SystemExit as status: | |
2555 | if status.code: |
|
2567 | if status.code: | |
2556 | raise |
|
2568 | raise |
@@ -587,7 +587,21 b' class Inspector(Colorable):' | |||||
587 | return bundle |
|
587 | return bundle | |
588 |
|
588 | |||
589 | def _get_info(self, obj, oname='', formatter=None, info=None, detail_level=0): |
|
589 | def _get_info(self, obj, oname='', formatter=None, info=None, detail_level=0): | |
590 |
"""Retrieve an info dict and format it. |
|
590 | """Retrieve an info dict and format it. | |
|
591 | ||||
|
592 | Parameters | |||
|
593 | ========== | |||
|
594 | ||||
|
595 | obj: any | |||
|
596 | Object to inspect and return info from | |||
|
597 | oname: str (default: ''): | |||
|
598 | Name of the variable pointing to `obj`. | |||
|
599 | formatter: callable | |||
|
600 | info: | |||
|
601 | already computed informations | |||
|
602 | detail_level: integer | |||
|
603 | Granularity of detail level, if set to 1, give more informations. | |||
|
604 | """ | |||
591 |
|
605 | |||
592 | info = self._info(obj, oname=oname, info=info, detail_level=detail_level) |
|
606 | info = self._info(obj, oname=oname, info=info, detail_level=detail_level) | |
593 |
|
607 | |||
@@ -696,24 +710,31 b' class Inspector(Colorable):' | |||||
696 | DeprecationWarning, stacklevel=2) |
|
710 | DeprecationWarning, stacklevel=2) | |
697 | return self._info(obj, oname=oname, info=info, detail_level=detail_level) |
|
711 | return self._info(obj, oname=oname, info=info, detail_level=detail_level) | |
698 |
|
712 | |||
699 | def _info(self, obj, oname='', info=None, detail_level=0): |
|
713 | def _info(self, obj, oname='', info=None, detail_level=0) -> dict: | |
700 | """Compute a dict with detailed information about an object. |
|
714 | """Compute a dict with detailed information about an object. | |
701 |
|
715 | |||
702 |
|
|
716 | Parameters | |
703 |
|
717 | ========== | ||
704 | - oname: name of the variable pointing to the object. |
|
718 | ||
705 |
|
719 | obj: any | ||
706 | - info: a structure with some information fields which may have been |
|
720 | An object to find information about | |
707 | precomputed already. |
|
721 | oname: str (default: ''): | |
708 |
|
722 | Name of the variable pointing to `obj`. | ||
709 | - detail_level: if set to 1, more information is given. |
|
723 | info: (default: None) | |
|
724 | A struct (dict like with attr access) with some information fields | |||
|
725 | which may have been precomputed already. | |||
|
726 | detail_level: int (default:0) | |||
|
727 | If set to 1, more information is given. | |||
|
728 | ||||
|
729 | Returns | |||
|
730 | ======= | |||
|
731 | ||||
|
732 | An object info dict with known fields from `info_fields`. | |||
710 | """ |
|
733 | """ | |
711 |
|
734 | |||
712 | obj_type = type(obj) |
|
|||
713 |
|
||||
714 | if info is None: |
|
735 | if info is None: | |
715 |
ismagic = |
|
736 | ismagic = False | |
716 |
isalias = |
|
737 | isalias = False | |
717 | ospace = '' |
|
738 | ospace = '' | |
718 | else: |
|
739 | else: | |
719 | ismagic = info.ismagic |
|
740 | ismagic = info.ismagic | |
@@ -743,17 +764,17 b' class Inspector(Colorable):' | |||||
743 | shalf = int((string_max - 5) / 2) |
|
764 | shalf = int((string_max - 5) / 2) | |
744 |
|
765 | |||
745 | if ismagic: |
|
766 | if ismagic: | |
746 |
o |
|
767 | out['type_name'] = 'Magic function' | |
747 | elif isalias: |
|
768 | elif isalias: | |
748 |
o |
|
769 | out['type_name'] = 'System alias' | |
749 | else: |
|
770 | else: | |
750 |
o |
|
771 | out['type_name'] = type(obj).__name__ | |
751 | out['type_name'] = obj_type_name |
|
|||
752 |
|
772 | |||
753 | try: |
|
773 | try: | |
754 | bclass = obj.__class__ |
|
774 | bclass = obj.__class__ | |
755 | out['base_class'] = str(bclass) |
|
775 | out['base_class'] = str(bclass) | |
756 |
except: |
|
776 | except: | |
|
777 | pass | |||
757 |
|
778 | |||
758 | # String form, but snip if too long in ? form (full in ??) |
|
779 | # String form, but snip if too long in ? form (full in ??) | |
759 | if detail_level >= self.str_detail_level: |
|
780 | if detail_level >= self.str_detail_level: | |
@@ -774,7 +795,8 b' class Inspector(Colorable):' | |||||
774 | # Length (for strings and lists) |
|
795 | # Length (for strings and lists) | |
775 | try: |
|
796 | try: | |
776 | out['length'] = str(len(obj)) |
|
797 | out['length'] = str(len(obj)) | |
777 |
except: |
|
798 | except Exception: | |
|
799 | pass | |||
778 |
|
800 | |||
779 | # Filename where object was defined |
|
801 | # Filename where object was defined | |
780 | binary_file = False |
|
802 | binary_file = False |
General Comments 0
You need to be logged in to leave comments.
Login now